Mawg
Mawg

Reputation: 40169

Send data in an HTTP header and get it back

I am coding some test software to simulate something like a router. It will send URL requests on behalf of multiple users.

Is there any HTTP GET header field which I can send which the receiving server will always send back to me unchanged in the response so that I can associate the response with a user?

This is test software for use on a local LAN only, so I don't mind misusing a field, just as long as I get it returned unchanged.

Upvotes: 1

Views: 692

Answers (2)

Seb
Seb

Reputation: 4586

One header that could be (ab)used for correlating requests and responses like this is Range.

Say each of your requests is labelled with a number i:

GET /index.html HTTP/1.1
Host: example.org
Range: bytes=5-1024
             ^
             i goes here

Then the server might respond with:

HTTP/1.1 206 Partial Content
Content-Range: bytes 5-1023/146515
                     ^
                     extract i from here

This does not satisfy your requirement that the header be returned "unchanged" but it's still easy to match up request and response, so it could fit some use cases.

Other caveats that may or may not matter:

  • It also modifies the response (and forces a status code of 206), returning one fewer byte for each successive request
  • The number of requests identified in this way is limited by the size of the requested resource (though you could use combinatorics to increase the domain by also varying the endpoint of the range)
  • Servers are not required to support range requests, so this might not work everywhere

Upvotes: 1

Iłya Bursov
Iłya Bursov

Reputation: 24146

according to http 1.1 rfc, response is:

  Response      = Status-Line               ; Section 6.1
                       *(( general-header        ; Section 4.5
                        | response-header        ; Section 6.2
                        | entity-header ) CRLF)  ; Section 7.1
                       CRLF
                       [ message-body ]          ; Section 7.2

and here is notation:

   *rule
      The character "*" preceding an element indicates repetition. The
      full form is "<n>*<m>element" indicating at least <n> and at most
      <m> occurrences of element. Default values are 0 and infinity so
      that "*(element)" allows any number, including zero; "1*element"
      requires at least one; and "1*2element" allows one or two.

   [rule]
      Square brackets enclose optional elements; "[foo bar]" is
      equivalent to "*1(foo bar)".

so, the only requirement for server is to respond with status code, other components are optional, always, which effectively means there is no requirement to send any header back

also, this contains list of all possible headers, none of them meet your requirements

I'm not sure about http 2.0, maybe somebody could add information about it

Upvotes: 2

Related Questions