Skip to content

feat: Support multiple HTTP headers with the same name#131

Merged
natesales merged 1 commit intonatesales:mainfrom
racpast:feat/support-duplicate-headers
Oct 28, 2025
Merged

feat: Support multiple HTTP headers with the same name#131
natesales merged 1 commit intonatesales:mainfrom
racpast:feat/support-duplicate-headers

Conversation

@racpast
Copy link
Copy Markdown
Contributor

@racpast racpast commented Oct 19, 2025

This PR adds support for specifying multiple HTTP headers with the same name for DoH queries, which is a standard feature of HTTP.

Problem:
Currently, if a user provides multiple --http-header flags with the same name (e.g., for cookies or other custom use cases), only the last one is used. This is because the headers are stored in a map[string]string, which overwrites previous values for the same key.

Solution:
I've made the following changes:

  1. Modified resolver.go to parse headers into a map[string][]string.
  2. Updated the transport.HTTP struct in transport/http.go to accept map[string][]string.
  3. Changed the request logic in transport/http.go to loop through all values for a given header name and use req.Header.Add() instead of req.Header.Set().

Verification

I have verified the fix using tshark to inspect the raw network traffic.

1. Start tshark to capture traffic:

tshark -i 4 -f "host 101.102.103.104" -o tls.keylog_file:"C:\temp\sslkeys.log" -Y http2 -V
  1. Run the modified q with duplicate custom headers:
set SSLKEYLOGFILE=C:\temp\sslkeys.log
q.exe -s https://101.102.103.104/dns-query -t A google.com --http2 -i --http-header "X-Test: value1" --http-header "X-Test: value2"
  1. tshark Output Confirmation: The captured HEADERS frame clearly shows that two separate X-Test headers were sent, confirming the fix is working correctly at the protocol level.
        Header: x-test: value1
            Name Length: 6
            Name: x-test
            Value Length: 6
            Value: value1
            [Unescaped: value1]
            Representation: Literal Header Field with Incremental Indexing - New Name
        Header: x-test: value2
            Name Length: 6
            Name: x-test
            Value Length: 6
            Value: value2
            [Unescaped: value2]
            Representation: Literal Header Field with Incremental Indexing - Indexed Name
            Index: 62

@natesales natesales merged commit 6b39451 into natesales:main Oct 28, 2025
1 of 2 checks passed
@racpast racpast deleted the feat/support-duplicate-headers branch October 28, 2025 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants