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

HTTP::Client: execute before_requestcallbacks right before writing the request #5626

Merged
merged 1 commit into from Jan 22, 2018
Merged

HTTP::Client: execute before_requestcallbacks right before writing the request #5626

merged 1 commit into from Jan 22, 2018

Conversation

asterite
Copy link
Member

This is a small refactor that makes before_request execute right before the request is executed. Right now a few headers are added later.

With this one can do:

require "http/client"

client = HTTP::Client.new("google.com", tls: true)
client.before_request &.to_io(STDOUT)
client.get("/").to_io(STDOUT)

And get:

GET / HTTP/1.1
Host: google.com
User-Agent: Crystal
Accept-Encoding: gzip, deflate

HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Location: https://www.google.com.ar/?gfe_rd=cr&dcr=0&ei=rttlWpvYNPTi8AfL-rFA
Content-Length: 271
Date: Mon, 22 Jan 2018 12:40:14 GMT
Alt-Svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="https://www.google.com.ar/?gfe_rd=cr&amp;dcr=0&amp;ei=rttlWpvYNPTi8AfL-rFA">here</A>.
</BODY></HTML>

@asterite asterite self-assigned this Jan 22, 2018
@asterite asterite added this to the Next milestone Jan 22, 2018
@asterite asterite merged commit ff02d2d into crystal-lang:master Jan 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants