Class: MockServer::HttpRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/mockserver/models.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method: nil, path: nil, query_string_parameters: nil, headers: nil, cookies: nil, body: nil, secure: nil, protocol: nil, keep_alive: nil, respond_before_body: nil, path_parameters: nil, socket_address: nil, jwt: nil, dns_name: nil, dns_type: nil, dns_class: nil) ⇒ HttpRequest

Returns a new instance of HttpRequest.



794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
# File 'lib/mockserver/models.rb', line 794

def initialize(method: nil, path: nil, query_string_parameters: nil, headers: nil,
               cookies: nil, body: nil, secure: nil, protocol: nil, keep_alive: nil,
               respond_before_body: nil, path_parameters: nil, socket_address: nil,
               jwt: nil, dns_name: nil, dns_type: nil, dns_class: nil)
  @method = method
  @path = path
  @query_string_parameters = query_string_parameters
  @headers = headers
  @cookies = cookies
  @body = body
  @secure = secure
  @protocol = protocol
  @keep_alive = keep_alive
  @respond_before_body = respond_before_body
  @path_parameters = path_parameters
  @socket_address = socket_address
  @jwt = jwt
  @dns_name = dns_name
  @dns_type = dns_type
  @dns_class = dns_class
end

Instance Attribute Details

#bodyObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def body
  @body
end

#cookiesObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def cookies
  @cookies
end

#dns_classObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def dns_class
  @dns_class
end

#dns_nameObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def dns_name
  @dns_name
end

#dns_typeObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def dns_type
  @dns_type
end

#headersObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def headers
  @headers
end

#jwtObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def jwt
  @jwt
end

#keep_aliveObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def keep_alive
  @keep_alive
end

#methodObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def method
  @method
end

#pathObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def path
  @path
end

#path_parametersObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def path_parameters
  @path_parameters
end

#protocolObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def protocol
  @protocol
end

#query_string_parametersObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def query_string_parameters
  @query_string_parameters
end

#respond_before_bodyObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def respond_before_body
  @respond_before_body
end

#secureObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def secure
  @secure
end

#socket_addressObject

dns_name / dns_type / dns_class carry a DNS request matcher (org.mockserver.model.DnsRequestDefinition). The server discriminates a DNS request definition from an HTTP one purely by the presence of a non-blank dnsName on the httpRequest object, so these fields round-trip through the same httpRequest slot as the HTTP matcher fields. protocol pins the transport the matcher requires (org.mockserver.model.Protocol: HTTP_1_1 / HTTP_2 / HTTP_3 / SOCKS / ...), round-tripping the httpRequest protocol wire key.



789
790
791
# File 'lib/mockserver/models.rb', line 789

def socket_address
  @socket_address
end

Class Method Details

.dns_request(dns_name, dns_type: nil, dns_class: nil) ⇒ Object

Build a DNS request matcher (org.mockserver.model.DnsRequestDefinition).



861
862
863
# File 'lib/mockserver/models.rb', line 861

def self.dns_request(dns_name, dns_type: nil, dns_class: nil)
  new(dns_name: dns_name, dns_type: dns_type, dns_class: dns_class)
end

.from_hash(data) ⇒ Object



837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
# File 'lib/mockserver/models.rb', line 837

def self.from_hash(data)
  return nil if data.nil?

  new(
    method:                  data['method'],
    path:                    data['path'],
    query_string_parameters: MockServer.deserialize_key_multi_values(data['queryStringParameters']),
    headers:                 MockServer.deserialize_key_multi_values(data['headers']),
    cookies:                 MockServer.deserialize_cookies(data['cookies']),
    body:                    MockServer.deserialize_body(data['body']),
    secure:                  data['secure'],
    protocol:                data['protocol'],
    keep_alive:              data['keepAlive'],
    respond_before_body:     data['respondBeforeBody'],
    path_parameters:         MockServer.deserialize_key_multi_values(data['pathParameters']),
    socket_address:          SocketAddress.from_hash(data['socketAddress']),
    jwt:                     Jwt.from_hash(data['jwt']),
    dns_name:                data['dnsName'],
    dns_type:                data['dnsType'],
    dns_class:               data['dnsClass']
  )
end

.request(path: nil) ⇒ Object



865
866
867
# File 'lib/mockserver/models.rb', line 865

def self.request(path: nil)
  new(path: path)
end

Instance Method Details

#to_hObject



816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
# File 'lib/mockserver/models.rb', line 816

def to_h
  MockServer.strip_none({
    'method'                => @method,
    'path'                  => @path,
    'queryStringParameters' => MockServer.serialize_key_multi_values(@query_string_parameters),
    'headers'               => MockServer.serialize_key_multi_values(@headers),
    'cookies'               => MockServer.serialize_cookies(@cookies),
    'body'                  => MockServer.serialize_body(@body),
    'secure'                => @secure,
    'protocol'              => @protocol,
    'keepAlive'             => @keep_alive,
    'respondBeforeBody'     => @respond_before_body,
    'pathParameters'        => MockServer.serialize_key_multi_values_object(@path_parameters),
    'socketAddress'         => @socket_address&.to_h,
    'jwt'                   => @jwt&.to_h,
    'dnsName'               => @dns_name,
    'dnsType'               => @dns_type,
    'dnsClass'              => @dns_class
  })
end

#with_body(body) ⇒ Object



897
898
899
900
# File 'lib/mockserver/models.rb', line 897

def with_body(body)
  @body = body
  self
end


891
892
893
894
895
# File 'lib/mockserver/models.rb', line 891

def with_cookie(name, value)
  @cookies ||= []
  @cookies << KeyToMultiValue.new(name: name, values: [value])
  self
end

#with_header(name, *values) ⇒ Object



879
880
881
882
883
# File 'lib/mockserver/models.rb', line 879

def with_header(name, *values)
  @headers ||= []
  @headers << KeyToMultiValue.new(name: name, values: values.flatten)
  self
end

#with_jwt(jwt) ⇒ Object



902
903
904
905
# File 'lib/mockserver/models.rb', line 902

def with_jwt(jwt)
  @jwt = jwt
  self
end

#with_keep_alive(keep_alive) ⇒ Object



912
913
914
915
# File 'lib/mockserver/models.rb', line 912

def with_keep_alive(keep_alive)
  @keep_alive = keep_alive
  self
end

#with_method(method) ⇒ Object



869
870
871
872
# File 'lib/mockserver/models.rb', line 869

def with_method(method)
  @method = method
  self
end

#with_path(path) ⇒ Object



874
875
876
877
# File 'lib/mockserver/models.rb', line 874

def with_path(path)
  @path = path
  self
end

#with_query_param(name, *values) ⇒ Object



885
886
887
888
889
# File 'lib/mockserver/models.rb', line 885

def with_query_param(name, *values)
  @query_string_parameters ||= []
  @query_string_parameters << KeyToMultiValue.new(name: name, values: values.flatten)
  self
end

#with_respond_before_body(respond_before_body) ⇒ Object



917
918
919
920
# File 'lib/mockserver/models.rb', line 917

def with_respond_before_body(respond_before_body)
  @respond_before_body = respond_before_body
  self
end

#with_secure(secure) ⇒ Object



907
908
909
910
# File 'lib/mockserver/models.rb', line 907

def with_secure(secure)
  @secure = secure
  self
end