Class: DataDomeHeaders

Inherits:
Object
  • Object
show all
Defined in:
lib/model/api/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addr: nil, client_ip: nil, content_type: nil, host: nil, port: nil, x_real_ip: nil, x_forwarded_for_ip: nil, accept_encoding: nil, accept_language: nil, accept: nil, method: nil, protocol: nil, server_hostname: nil, referer: nil, user_agent: nil, from: nil, request: nil, origin: nil, accept_charset: nil, connection: nil, client_id: nil, sec_ch_ua: nil, sec_ch_ua_mobile: nil, sec_ch_ua_platform: nil, sec_ch_ua_arch: nil, sec_ch_ua_full_version_list: nil, sec_ch_ua_model: nil, sec_ch_device_memory: nil) ⇒ DataDomeHeaders

Returns a new instance of DataDomeHeaders.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/model/api/request.rb', line 30

def initialize(addr: nil, client_ip: nil, content_type: nil, host: nil, port: nil, x_real_ip: nil,
               x_forwarded_for_ip: nil, accept_encoding: nil, accept_language: nil, accept: nil,
               method: nil, protocol: nil, server_hostname: nil, referer: nil, user_agent: nil,
               from: nil, request: nil, origin: nil, accept_charset: nil, connection: nil,
               client_id: nil, sec_ch_ua: nil, sec_ch_ua_mobile: nil, sec_ch_ua_platform: nil,
               sec_ch_ua_arch: nil, sec_ch_ua_full_version_list: nil, sec_ch_ua_model: nil,
               sec_ch_device_memory: nil)
  @addr = addr
  @client_ip = client_ip
  @content_type = content_type
  @host = host
  @port = port
  @x_real_ip = x_real_ip
  @x_forwarded_for_ip = x_forwarded_for_ip
  @accept_encoding = accept_encoding
  @accept_language = accept_language
  @accept = accept
  @method = method
  @protocol = protocol
  @server_hostname = server_hostname
  @referer = referer
  @user_agent = user_agent
  @from = from
  @request = request
  @origin = origin
  @accept_charset = accept_charset
  @connection = connection
  @client_id = client_id
  @sec_ch_ua = sec_ch_ua
  @sec_ch_ua_mobile = sec_ch_ua_mobile
  @sec_ch_ua_platform = sec_ch_ua_platform
  @sec_ch_ua_arch = sec_ch_ua_arch
  @sec_ch_ua_full_version_list = sec_ch_ua_full_version_list
  @sec_ch_ua_model = sec_ch_ua_model
  @sec_ch_device_memory = sec_ch_device_memory
end

Instance Attribute Details

#acceptObject

Returns the value of attribute accept.



24
25
26
# File 'lib/model/api/request.rb', line 24

def accept
  @accept
end

#accept_charsetObject

Returns the value of attribute accept_charset.



24
25
26
# File 'lib/model/api/request.rb', line 24

def accept_charset
  @accept_charset
end

#accept_encodingObject

Returns the value of attribute accept_encoding.



24
25
26
# File 'lib/model/api/request.rb', line 24

def accept_encoding
  @accept_encoding
end

#accept_languageObject

Returns the value of attribute accept_language.



24
25
26
# File 'lib/model/api/request.rb', line 24

def accept_language
  @accept_language
end

#addrObject

Returns the value of attribute addr.



24
25
26
# File 'lib/model/api/request.rb', line 24

def addr
  @addr
end

#client_idObject

Returns the value of attribute client_id.



24
25
26
# File 'lib/model/api/request.rb', line 24

def client_id
  @client_id
end

#client_ipObject

Returns the value of attribute client_ip.



24
25
26
# File 'lib/model/api/request.rb', line 24

def client_ip
  @client_ip
end

#connectionObject

Returns the value of attribute connection.



24
25
26
# File 'lib/model/api/request.rb', line 24

def connection
  @connection
end

#content_typeObject

Returns the value of attribute content_type.



24
25
26
# File 'lib/model/api/request.rb', line 24

def content_type
  @content_type
end

#fromObject

Returns the value of attribute from.



24
25
26
# File 'lib/model/api/request.rb', line 24

def from
  @from
end

#hostObject

Returns the value of attribute host.



24
25
26
# File 'lib/model/api/request.rb', line 24

def host
  @host
end

#methodObject

Returns the value of attribute method.



24
25
26
# File 'lib/model/api/request.rb', line 24

def method
  @method
end

#originObject

Returns the value of attribute origin.



24
25
26
# File 'lib/model/api/request.rb', line 24

def origin
  @origin
end

#portObject

Returns the value of attribute port.



24
25
26
# File 'lib/model/api/request.rb', line 24

def port
  @port
end

#protocolObject

Returns the value of attribute protocol.



24
25
26
# File 'lib/model/api/request.rb', line 24

def protocol
  @protocol
end

#refererObject

Returns the value of attribute referer.



24
25
26
# File 'lib/model/api/request.rb', line 24

def referer
  @referer
end

#requestObject

Returns the value of attribute request.



24
25
26
# File 'lib/model/api/request.rb', line 24

def request
  @request
end

#sec_ch_device_memoryObject

Returns the value of attribute sec_ch_device_memory.



24
25
26
# File 'lib/model/api/request.rb', line 24

def sec_ch_device_memory
  @sec_ch_device_memory
end

#sec_ch_uaObject

Returns the value of attribute sec_ch_ua.



24
25
26
# File 'lib/model/api/request.rb', line 24

def sec_ch_ua
  @sec_ch_ua
end

#sec_ch_ua_archObject

Returns the value of attribute sec_ch_ua_arch.



24
25
26
# File 'lib/model/api/request.rb', line 24

def sec_ch_ua_arch
  @sec_ch_ua_arch
end

#sec_ch_ua_full_version_listObject

Returns the value of attribute sec_ch_ua_full_version_list.



24
25
26
# File 'lib/model/api/request.rb', line 24

def sec_ch_ua_full_version_list
  @sec_ch_ua_full_version_list
end

#sec_ch_ua_mobileObject

Returns the value of attribute sec_ch_ua_mobile.



24
25
26
# File 'lib/model/api/request.rb', line 24

def sec_ch_ua_mobile
  @sec_ch_ua_mobile
end

#sec_ch_ua_modelObject

Returns the value of attribute sec_ch_ua_model.



24
25
26
# File 'lib/model/api/request.rb', line 24

def sec_ch_ua_model
  @sec_ch_ua_model
end

#sec_ch_ua_platformObject

Returns the value of attribute sec_ch_ua_platform.



24
25
26
# File 'lib/model/api/request.rb', line 24

def sec_ch_ua_platform
  @sec_ch_ua_platform
end

#server_hostnameObject

Returns the value of attribute server_hostname.



24
25
26
# File 'lib/model/api/request.rb', line 24

def server_hostname
  @server_hostname
end

#user_agentObject

Returns the value of attribute user_agent.



24
25
26
# File 'lib/model/api/request.rb', line 24

def user_agent
  @user_agent
end

#x_forwarded_for_ipObject

Returns the value of attribute x_forwarded_for_ip.



24
25
26
# File 'lib/model/api/request.rb', line 24

def x_forwarded_for_ip
  @x_forwarded_for_ip
end

#x_real_ipObject

Returns the value of attribute x_real_ip.



24
25
26
# File 'lib/model/api/request.rb', line 24

def x_real_ip
  @x_real_ip
end

Instance Method Details

#build_from_http_request(request) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/model/api/request.rb', line 67

def build_from_http_request(request)
  @addr = request.remote_ip
  @client_ip = request.headers["HTTP_CLIENT_IP"]
  @content_type = request.headers["Content-Type"] # this value is a meta-variable of the request
  @host = request.headers["HTTP_HOST"]
  @port = request.port || 0
  @x_real_ip = request.headers["HTTP_X_REAL_IP"]
  @x_forwarded_for_ip = request.headers["HTTP_X_FORWARDED_FOR"]
  @accept_encoding = request.headers["HTTP_ACCEPT_ENCODING"]
  @accept_language = request.headers["HTTP_ACCEPT_LANGUAGE"]
  @accept = request.headers["HTTP_ACCEPT"]
  @method = request.method
  @protocol = request.protocol.gsub("://", "")
  @server_hostname = request.headers["HTTP_HOST"]
  @referer = request.headers["HTTP_REFERER"]
  @user_agent = request.headers["HTTP_USER_AGENT"]
  @from = request.headers["HTTP_FROM"]
  @request = [request.path, request.query_string].reject(&:blank?).join("?")
  @origin = request.headers["HTTP_ORIGIN"]
  @accept_charset = request.headers["HTTP_ACCEPT_CHARSET"]
  @connection = request.headers["HTTP_CONNECTION"]
  @client_id = request.cookies["datadome"]
  @sec_ch_ua = request.headers["HTTP_SEC_CH_UA"]
  @sec_ch_ua_mobile = request.headers["HTTP_SEC_CH_UA_MOBILE"]
  @sec_ch_ua_platform = request.headers["HTTP_SEC_CH_UA_PLATFORM"]
  @sec_ch_ua_arch = request.headers["HTTP_SEC_CH_UA_ARCH"]
  @sec_ch_ua_full_version_list = request.headers["HTTP_SEC_CH_UA_FULL_VERSION_LIST"]
  @sec_ch_ua_model = request.headers["HTTP_SEC_CH_UA_MODEL"]
  @sec_ch_device_memory = request.headers["HTTP_SEC_CH_DEVICE_MEMORY"]
end

#to_hashObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/model/api/request.rb', line 145

def to_hash
  {
    addr: @addr,
    clientIp: @client_ip,
    contentType: @content_type,
    host: @host,
    port: @port,
    xRealIP: @x_real_ip,
    xForwardedForIp: @x_forwarded_for_ip,
    acceptEncoding: @accept_encoding,
    acceptLanguage: @accept_language,
    accept: @accept,
    method: @method,
    protocol: @protocol,
    serverHostname: @server_hostname,
    referer: @referer,
    userAgent: @user_agent,
    from: @from,
    request: @request,
    origin: @origin,
    acceptCharset: @accept_charset,
    connection: @connection,
    clientID: @client_id,
    secCHUA: @sec_ch_ua,
    secCHUAMobile: @sec_ch_ua_mobile,
    secCHUAPlatform: @sec_ch_ua_platform,
    secCHUAArch: @sec_ch_ua_arch,
    secCHUAFullVersionList: @sec_ch_ua_full_version_list,
    secCHUAModel: @sec_ch_ua_model,
    secCHDeviceMemory: @sec_ch_device_memory,
  }
end

#truncate_attributesObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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
# File 'lib/model/api/request.rb', line 98

def truncate_attributes
  # Hash containing the headers size limit
  headers_max_length = {
    addr: nil, # No size limit
    client_ip: nil,
    content_type: 64,
    host: 512,
    port: nil,
    x_real_ip: 128,
    x_forwarded_for_ip: -512, # Truncate backwards
    accept_encoding: 128,
    accept_language: 256,
    accept: 512,
    method: nil,
    protocol: nil,
    server_hostname: 256,
    referer: 1024,
    user_agent: 768,
    from: 128,
    request: 2048,
    origin: 512,
    accept_charset: 128,
    connection: 128,
    client_id: nil,
    sec_ch_ua: 128,
    sec_ch_ua_mobile: 8,
    sec_ch_ua_platform: 32,
    sec_ch_ua_arch: 16,
    sec_ch_ua_full_version_list: 256,
    sec_ch_ua_model: 128,
    sec_ch_device_memory: 8,
  }

  headers_max_length.each do |attribute, max_size|
    next unless self.respond_to?("#{attribute}=") # Skip if attribute setter method doesn't exist

    value = self.send(attribute) # Get the value of the attribute dynamically
    next unless value.is_a?(String) # Skip if the value is not a string

    if max_size && value.length > max_size
      # Truncate the value if it exceeds the max size
      truncated_value = max_size < 0 ? value[max_size] : value[0, max_size]
      self.send("#{attribute}=", truncated_value) # Set the truncated value to the attribute
    end
  end
end