-
Notifications
You must be signed in to change notification settings - Fork 321
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
Content-Length not being set for POST requests? #335
Comments
You're correct we should be sending Content-Length if the length of the request body is known in advance. That said, in your case the request body is empty, so sending an arbitrary length like that will hang the remote server as it waits for the rest of the body. |
Ah no wonder, it's just strange that the reCaptcha server has this set. I wonder if we could add some log notification if the gem if waiting for rest of the body and there isn't any response after a certain timeout? It's just to potentially prevent others seeing something similar, even though I'd agree this is not a typical use-case. Cheers @tarcieri |
This gem has extensive timeout support: https://github.com/httprb/http/wiki/Timeouts |
Ooh fantastic, thanks. |
This does the trick, thanks! HTTP[content_length: 0]. \
timeout(write: 2, connect: 5, read: 20). \
post('https://www.google.com/recaptcha/api/siteverify', params: {
secret: secret, response: response
})
=> {"success"=>true,
"challenge_ts"=>"2016-04-25T15:53:14Z",
"hostname"=>"localhost"} |
Reopening as we should probably set the request Content-Length if it's known in advance. |
Resolved by #360 |
## 2.0.3 (2016-08-03) * [#365](httprb/http#365) Add `HTTP::Response#content_length` ([@janko-m]) * [#335](httprb/http#335), [#360](httprb/http#360) Set `Content-Length: 0` header for `nil` bodies. ([@britishtea]) ## 2.0.2 (2016-06-24) * [#353](httprb/http#353) Avoid a dependency cycle between Client and Connection classes. ([@jhbabon]) ## 2.0.1 (2016-05-12) * [#341](httprb/http#341) Refactor some string manipulations so they are more performant (up to 3-4x faster) and more concise. ([@tonyta]) * [#339](httprb/http#341) Always use byte methods when writing/slicing the write buffer. ([@zanker]) ## 2.0.0 (2016-04-23) * [#333](httprb/http#333) Fix HTTPS request headline when sent via proxy. ([@Connorhd]) * [#331](httprb/http#331) Add `#informational?`, `#success?`, `#redirect?`, `#client_error?` and `#server_error?` helpers to `Response::Status`. ([@mwitek]) * [#330](httprb/http#330) Support custom CONNECT headers (request/response) during HTTPS proxy requests. ([@smudge]) * [#319](httprb/http#319) Drop Ruby 1.9.x support. ([@ixti]) ## 1.0.4 (2016-03-19) * [#320](httprb/http#320) Fix timeout regression. ([@tarcieri]) ## 1.0.3 (2016-03-16) * [#314](httprb/http#314) Validate charset before forcing encoding. ([@kylekyle]) * [#318](httprb/http#318) Remove redundant string allocations upon header names normalization. ([@ixti])
Hi,
I was integrating reCaptcha today and can into something curious,
HTTP.post('https://www.google.com/recaptcha/api/siteverify', params: { secret: secret, response: response })
and gotI tried setting the content length to some random value but I found it would hang of I did,
I suppose, this is because the content length is invalid; I didn't have time prying into the library to figure this out as I've gotten HTTParty working just fine.
Thanks!
The text was updated successfully, but these errors were encountered: