Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow viewing request headers #8

Merged
merged 2 commits into from Sep 13, 2017
Merged

Conversation

akostadinov
Copy link
Contributor

Made this modification to aid testing. Thought might be useful for the example.

@akostadinov
Copy link
Contributor Author

bump

@bparees
Copy link
Contributor

bparees commented Aug 16, 2017

@coreydaley ptal

config.ru Outdated
headers = proc do |env|
[200, { "Content-Type" => "text/html" }, [
env.select {|key,val| key.start_with? 'HTTP_'}
.collect {|key, val| [key.sub(/^HTTP_/, ''), val]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave the HTTP_ prefix on the headers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original headers don't have HTTP_ prefix. AFAIK it is rack that puts them into env by adding the prefix. So HTTP_ is not actually part of the header name. See http://www.rubydoc.info/github/rack/rack/file/SPEC

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine then.

config.ru Outdated
.join("<br/>\n")
]]
end
run headers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have this output properly formatted HTML as the root route does

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Firefox it shows "Quirks mode". HTML is very minimal. Just <br/> for new lines and strings are HTML escaped for proper output.

In any case here is an example raw output of current implementation:

ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8<br/>
ACCEPT_ENCODING: gzip, deflate<br/>
ACCEPT_LANGUAGE: bg,en-US;q=0.7,en;q=0.3<br/>
COOKIE: s_fid=1C893BDD6A1DFF78-0BE36C33F7C57F7E; s_vi=[CS]v1|2CB1B999851D4D11-60000136A00064DA[AC]; AMCV_945F02BE332957400A490D4C%40AdobeOrg=-<snip for security>4882679239%26vn%3D12<br/>
DNT: 1<br/>
FORWARDED: for=10.3.2.11;host=ruby-ex-aosqe.example.com;proto=http<br/>
HOST: ruby-ex-aosqe..com<br/>
UPGRADE_INSECURE_REQUESTS: 1<br/>
USER_AGENT: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0<br/>
VERSION: HTTP/1.1<br/>
X_FORWARDED_FOR: 10.3.2.11<br/>
X_FORWARDED_HOST: ruby-ex-aosqe.example.com<br/>
X_FORWARDED_PORT: 80<br/>
X_FORWARDED_PROTO: http

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you specify more precisely what should properly formatted HTML mean? With html and head tags? Or something more? Alternatively probably this can serve text/plain instead of "text/html". WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either wrap it in html and head etc, or specifying text/plain would probably be a better solution

@akostadinov
Copy link
Contributor Author

Sorry for delay, updated to send text/plain instead of broken HTML. I added a commit for easier review of the changes. If you don't see any possible improvements, please squash merge or let me know to squash by myself.

@akostadinov
Copy link
Contributor Author

$ curl -v http://ruby-ex-2ok3c.0912-smr.qe.rhcloud.com/headers
*   Trying 10.8.241.13...
* TCP_NODELAY set
* Connected to ruby-ex-2ok3c.0912-smr.qe.rhcloud.com (10.8.241.13) port 80 (#0)
> GET /headers HTTP/1.1
> Host: ruby-ex-2ok3c.0912-smr.qe.rhcloud.com
> User-Agent: curl/7.53.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: text/plain
< Content-Length: 312
< Set-Cookie: d86818b434af347f5aa8b626ac47ada9=7baa41ffbb8b5f79a782e7335d360671; path=/; HttpOnly
< Cache-control: private
< 
ACCEPT: */*
FORWARDED: for=10.36.116.170;host=ruby-ex-2ok3c.0912-smr.qe.rhcloud.com;proto=http
HOST: ruby-ex-2ok3c.0912-smr.qe.rhcloud.com
USER_AGENT: curl/7.53.1
VERSION: HTTP/1.1
X_FORWARDED_FOR: 10.36.116.170
X_FORWARDED_HOST: ruby-ex-2ok3c.0912-smr.qe.rhcloud.com
X_FORWARDED_PORT: 80
X_FORWARDED_PROTO: http

I checked that it looks ok in browsers as well.

@coreydaley
Copy link
Contributor

@bparees lgtm

@bparees bparees merged commit 5ce019b into sclorg:master Sep 13, 2017
sallyom pushed a commit to sallyom/ruby-ex that referenced this pull request Sep 15, 2017
* allow viewing request headers

* text/plain output for headers
xcoulon pushed a commit to xcoulon/ruby-ex that referenced this pull request Mar 28, 2023
* allow viewing request headers

* text/plain output for headers
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.

None yet

3 participants