Sha256: 8487337b69dca57e458ad7fc4db8fbb819d9c57dc00e0df49c32a2d4506a8b85

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require 'json'
require_relative 'http_request'
require_relative 'http_response'

module Akita
  module HarLogger
    # Encapsulates an HTTP request-response pair.
    class HarEntry
      attr_reader :request, :response

      # Params:
      # +start_time+:: a Time object representing the request's start time.
      # +env+:: the request's HTTP environment.
      # +status+:: the response's HTTP status code.
      # +headers+:: the response's HTTP headers.
      # +body+:: the response's HTTP body.
      def initialize(start_time, wait_time_ms, env, status, headers, body)
        @self = {
          startedDateTime: start_time.strftime('%FT%T.%L%:z'),
          time: wait_time_ms,
          request: (HttpRequest.new env),
          response: (HttpResponse.new env, status, headers, body),
          cache: {},  # Not applicable to server-side logging.
          timings: {
            send: 0,  # Mandatory, but not applicable to server-side logging.
            wait: wait_time_ms,
            receive: 0,  # Mandatory, but not applicable to server-side logging.
          },
        }
      end

      def to_json(*args)
        @self.to_json(*args)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
akita-har_logger-0.2.1 lib/akita/har_logger/har_entry.rb
akita-har_logger-0.2.0 lib/akita/har_logger/har_entry.rb
akita-har_logger-0.1.0 lib/akita/har_logger/har_entry.rb