httpbin icon indicating copy to clipboard operation
httpbin copied to clipboard

/headers does not show Via header

Open filex opened this issue 8 years ago • 8 comments

curl -s -H x-via:bar -H via:foo 'https://httpbin.org/headers' | jq .
{
  "headers": {
    "Accept": "*/*",
    "Connection": "close",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.54.0",
    "X-Via": "bar"
  }
}

The via header does not show up in the result, while x-via does. I would expect both header to be reflected.

filex avatar May 18 '18 09:05 filex

Can you try this with a locally running version of httpbin? This is almost certainly due to the fact that we host HTTPbin on Heroku and that has a proxy which strips and/or replaces certain headers.

sigmavirus24 avatar May 18 '18 10:05 sigmavirus24

I have used the docker image:

$ docker run -p 1234:80 kennethreitz/httpbin
[2018-05-18 11:44:26 +0000] [1] [INFO] Starting gunicorn 19.8.1
[2018-05-18 11:44:26 +0000] [1] [INFO] Listening at: http://0.0.0.0:80 (1)
[2018-05-18 11:44:26 +0000] [1] [INFO] Using worker: gevent
[2018-05-18 11:44:26 +0000] [8] [INFO] Booting worker with pid: 8

…

But the via header still does not appear:

$ curl -s -H x-via:bar -H via:foo 'http://localhost:1234/headers' | jq .
{
  "headers": {
    "Accept": "*/*",
    "Host": "localhost:1234",
    "User-Agent": "curl/7.54.0",
    "X-Via": "bar"
  }
}

filex avatar May 18 '18 11:05 filex

Thanks for confirming.

sigmavirus24 avatar May 18 '18 14:05 sigmavirus24

So we have a list of ENV_HEADERS with which we strip things out like Via. We need to switch to using get_headers in our view function with a query parameter to toggle the behaviour of hiding the environment or not.

I'd be happy to merge a pull request that does that.

sigmavirus24 avatar May 18 '18 14:05 sigmavirus24

@sigmavirus24 Fixed it in #457. Please let me know if anything else is needed.

sanketsaurav avatar May 19 '18 15:05 sanketsaurav

I didn't new about the show_env param. Apparently it is already working for /headers in master (and online):

curl -s -H x-via:bar -H via:foo 'https://httpbin.org/headers?show_env' | jq .
{
  "headers": {
    "Accept": "*/*",
    "Connect-Time": "1",
    "Connection": "close",
    "Host": "httpbin.org",
    "Total-Route-Time": "0",
    "User-Agent": "curl/7.54.0",
    "Via": "foo, 1.1 vegur",
    "X-Forwarded-For": "78.34.241.215",
    "X-Forwarded-Port": "443",
    "X-Forwarded-Proto": "https",
    "X-Request-Id": "24a06c7f-10ff-4b10-9984-b5c1e17203cc",
    "X-Request-Start": "1526745534478",
    "X-Via": "bar"
  }
}

filex avatar May 19 '18 16:05 filex

@sanketsaurav What is the reason that these headers are not shown by default, since this would make the usage of the swagger UI much more intuitive?

(I used httpbin to examine the headers set by my load balancer and needed a serious amount of time to figure out that the load balancer is working properly and httpbin is just not showing the X-FORWARDED-FOR header)

CapoD avatar Apr 09 '20 09:04 CapoD

Also note that the values of X-Forwarded-Proto and X-Forwarded-Port in the request are overridden according to whether it's an http or https call that is made.

sohamsengupta17 avatar Apr 18 '23 19:04 sohamsengupta17