Class: Sqreen::Kit::Signals::Context::HttpContext

Inherits:
Object
  • Object
show all
Includes:
DtoHelper
Defined in:
lib/sqreen/kit/signals/context/http_context.rb

Constant Summary collapse

PARAMS_ATTRS =
[:params_query, :params_form, :params_cookies,
:params_json, :params_other].freeze
SCHEMA_VERSION =
'http/2020-01-01T00:00:00.000Z'.freeze

Constants included from DtoHelper

DtoHelper::DO_NOT_CONVERT_TYPES, DtoHelper::RFC_3339_FMT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DtoHelper

#append_to_h_filter, #compact_hash, included, #initialize, #to_json

Instance Attribute Details

#content_lengthInteger

Response content length

Returns:

  • (Integer)


104
105
106
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 104

def content_length
  @content_length
end

#content_typeString

Response content type

Returns:

  • (String)


108
109
110
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 108

def content_type
  @content_type
end

#datadog_span_idInteger

Datadog span id

Returns:

  • (Integer)


116
117
118
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 116

def datadog_span_id
  @datadog_span_id
end

#datadog_trace_idInteger

Datadog trace id

Returns:

  • (Integer)


112
113
114
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 112

def datadog_trace_id
  @datadog_trace_id
end

#endpointString

Returns:

  • (String)


93
94
95
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 93

def endpoint
  @endpoint
end

#headersArray<Array<String>>

mandatory

Returns:

  • (Array<Array<String>>)

    inner arrays have two values: [name, value]



34
35
36
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 34

def headers
  @headers
end

#hostString

mandatory Host header; may include the port

Returns:

  • (String)


55
56
57
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 55

def host
  @host
end

#params_cookiesHash

Returns:

  • (Hash)


84
85
86
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 84

def params_cookies
  @params_cookies
end

#params_formHash

Returns:

  • (Hash)


81
82
83
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 81

def params_form
  @params_form
end

#params_jsonHash

Returns:

  • (Hash)


87
88
89
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 87

def params_json
  @params_json
end

#params_otherHash

Returns:

  • (Hash)


90
91
92
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 90

def params_other
  @params_other
end

#params_queryHash

Returns:

  • (Hash)


78
79
80
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 78

def params_query
  @params_query
end

#pathString

mandatory XXX: Unclear is decoded or not

Returns:

  • (String)


72
73
74
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 72

def path
  @path
end

#portInteger|String

mandatory

Returns:

  • (Integer|String)


59
60
61
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 59

def port
  @port
end

#refererString

Returns:

  • (String)


75
76
77
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 75

def referer
  @referer
end

#remote_ipString

mandatory

Returns:

  • (String)


63
64
65
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 63

def remote_ip
  @remote_ip
end

#remote_portInteger|String

mandatory

Returns:

  • (Integer|String)


67
68
69
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 67

def remote_port
  @remote_port
end

#reveal_replayedBoolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 96

def reveal_replayed
  @reveal_replayed
end

#ridString

Returns:

  • (String)


30
31
32
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 30

def rid
  @rid
end

#schemeString

mandatory

Returns:

  • (String)


42
43
44
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 42

def scheme
  @scheme
end

#statusInteger

Response status

Returns:

  • (Integer)


100
101
102
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 100

def status
  @status
end

#user_agentString

mandatory

Returns:

  • (String)


38
39
40
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 38

def user_agent
  @user_agent
end

#verbObject



47
48
49
50
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 47

def verb
  raise 'verb not set' unless defined?(@verb) && @verb
  @verb.upcase
end

Instance Method Details

#to_hObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/sqreen/kit/signals/context/http_context.rb', line 118

def to_h
  check_mandatories

  {
    request: compact_hash({
                            rid: rid,
                            headers: headers,
                            user_agent: user_agent,
                            scheme: scheme,
                            verb: verb,
                            host: host,
                            port: port,
                            remote_ip: remote_ip,
                            remote_port: remote_port,
                            path: path,
                            referer: referer,
                            parameters: compact_hash({
                                                       query: params_query,
                                                       form: params_form,
                                                       cookies: params_cookies,
                                                       json: params_json,
                                                       other: params_other,
                                                     }),
                            endpoint: endpoint,
                            # yes, this one is in CamelCase
                            isRevealReplayed: reveal_replayed,
                          }),
    response: compact_hash({
                             status: status,
                             content_type: content_type,
                             content_length: content_length,
                           }),
  }.merge!(compact_hash(
             datadog_trace_id: datadog_trace_id,
             datadog_span_id: datadog_span_id,
  ))
end