Skip to content

Header order is not maintained when headers or header_options are passed as options to GET method call #1

Description

@moya1295

Summary:

Header Orders are not maintained when headers or header_options are added to options in GET method call arguments.

Reproduction Script:

require 'wreq-rb'
require 'json'

url= "https://tls.peet.ws/api/all"

headers = {
  "a" => "1",
  "b" => "2",
  "c" => "3",
  "d" => "4",
}

header_order = [
  "a",
  "b",
  "c",
  "d",
]

options = {
  headers: headers,
  header_order: header_order,
  emulation: "edge_145",
}

puts "Test #1: set options on client Only"
client_1 = Wreq::Client.new(**options)
response_1 = client_1.get(url)
headers_1 = JSON.parse(response_1.text)["http2"]["sent_frames"][2]["headers"]
puts headers_1
puts "\n\n"

puts "Test #2: set options on client and get method"
client_2 = Wreq::Client.new(**options)
response_2 = client_2.get(url, **options)
headers_2 = JSON.parse(response_2.text)["http2"]["sent_frames"][2]["headers"]
puts headers_2
puts "\n\n"

puts "Test #3: set options on client and get method except header_order"
client_3 = Wreq::Client.new(**options)
response_3 = client_3.get(url, **options.slice(:header_order))
headers_3 = JSON.parse(response_3.text)["http2"]["sent_frames"][2]["headers"]
puts headers_3
puts "\n\n"

puts "Test #4: set options on client and get method except emulation"
client_4 = Wreq::Client.new(**options)
response_4 = client_4.get(url, **options.slice(:emulation))
headers_4 = JSON.parse(response_4.text)["http2"]["sent_frames"][2]["headers"]
puts headers_4
puts "\n\n"

puts "Test #5: set options on client and get method except headers"
client_5 = Wreq::Client.new(**options)
response_5 = client_5.get(url, **options.slice(:headers))
headers_5 = JSON.parse(response_5.text)["http2"]["sent_frames"][2]["headers"]
puts headers_5

Test # 2 and Test # 4 do not maintain header order.
Output:

Test #1: set options on client Only
:method: GET
:authority: tls.peet.ws
:scheme: https
:path: /api/all
a: 1
b: 2
c: 3
d: 4
sec-ch-ua: \"Chromium\";v=\"145\", \"Not;A=Brand\";v=\"24\", \"Microsoft Edge\";v=\"145\
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: \"macOS\
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0
sec-fetch-dest: document
sec-fetch-mode: navigate
sec-fetch-site: none
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br, zstd
accept-language: en-US,en;q=0.9
priority: u=0, i


Test #2: set options on client and get method
:method: GET
:authority: tls.peet.ws
:scheme: https
:path: /api/all
sec-ch-ua: \"Chromium\";v=\"145\", \"Not;A=Brand\";v=\"24\", \"Microsoft Edge\";v=\"145\
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: \"macOS\
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0
sec-fetch-dest: document
sec-fetch-mode: navigate
sec-fetch-site: none
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br, zstd
accept-language: en-US,en;q=0.9
priority: u=0, i
a: 1
b: 2
c: 3
d: 4


Test #3: set options on client and get method except header_order
:method: GET
:authority: tls.peet.ws
:scheme: https
:path: /api/all
a: 1
b: 2
c: 3
d: 4
sec-ch-ua: \"Chromium\";v=\"145\", \"Not;A=Brand\";v=\"24\", \"Microsoft Edge\";v=\"145\
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: \"macOS\
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0
sec-fetch-dest: document
sec-fetch-mode: navigate
sec-fetch-site: none
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br, zstd
accept-language: en-US,en;q=0.9
priority: u=0, i


Test #4: set options on client and get method except emulation
:method: GET
:authority: tls.peet.ws
:scheme: https
:path: /api/all
sec-ch-ua: \"Chromium\";v=\"145\", \"Not;A=Brand\";v=\"24\", \"Microsoft Edge\";v=\"145\
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: \"macOS\
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0
sec-fetch-dest: document
sec-fetch-mode: navigate
sec-fetch-site: none
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br, zstd
accept-language: en-US,en;q=0.9
priority: u=0, i
a: 1
b: 2
c: 3
d: 4


Test #5: set options on client and get method except headers
:method: GET
:authority: tls.peet.ws
:scheme: https
:path: /api/all
a: 1
b: 2
c: 3
d: 4
sec-ch-ua: \"Chromium\";v=\"145\", \"Not;A=Brand\";v=\"24\", \"Microsoft Edge\";v=\"145\
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: \"macOS\
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0
sec-fetch-dest: document
sec-fetch-mode: navigate
sec-fetch-site: none
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br, zstd
accept-language: en-US,en;q=0.9
priority: u=0, i

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions