-
Notifications
You must be signed in to change notification settings - Fork 150
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
Connection Options for em-httprequest #88
Comments
So with the request: <HTTPI::Request:0x007f9368dd5268
@body=
"MY_BODY",
@headers=
{"MY_HEADERS},
@open_timeout=60,
@read_timeout=120,
@url=MY_URL> HTTPI::Adapter::EmHttpRequest is constructed, which calls: @client = EventMachine::HttpRequest.new build_request_url(request.url) But EventMachine::HttpRequest constructor is: def self.new(uri, options={})
connopt = HttpConnectionOptions.new(uri, options)
c = HttpConnection.new
c.connopts = connopt
c.uri = uri
c
end so the HttpConnectionOptions never gets the options for the timeout, it only get the url, so it ends using the default options on the class HttpConnectionOptions, which includes a default connect timeout of 5 seconds and a inactivity timeout of 10 seconds. |
Another thing, is that I saw that the options for timeout are passed when the request is made, on HTTPI::Adapter.request: def request(method)
_request { |options| @client.send method, options }
end that will hit EventMachine::HTTPMethods.setup_request, which uses the options and pass it to the constructor of HttpClientOptions, but this constructor expects options like:
No way to send the timeout flags at this time, so definetly they should be sent when the EventMachine::HttpRequest is created. A monkey patch: module HTTPI
module Adapter
class EmHttpRequest < Base
def initialize(request)
@request = request
@client = EventMachine::HttpRequest.new(
build_request_url(request.url),
{connect_timeout: request.open_timeout, inactivity_timeout: request.read_timeout}
)
end
end
end
end if you let me know if that code can actually be merged, and that it make sense, then I'll work on the rspec and do a pull request. |
thanks @rorra. if it's backed by specs, i think we should get your fix in. |
@rorra thanks for all the info you put here! def initialize(request)
@request = request
@client = EventMachine::HttpRequest.new(
build_request_url(request.url),
self.client_options
)
end Go ahead with the pull request! 😄 |
Looking to the sources, only HttpConnectionOptions accept |
I think that the problem by using self.client_options, is that the options that em-httprequest expects are not the same options that httpi has, that's the reason I did the transformation inline: {connect_timeout: request.open_timeout, inactivity_timeout: request.read_timeout} httpi has open_timeout and read_timeout, while em-httprequest has connect_timeout and inactivity_timeout, and I bet its probably the same with other options like the proxy. I'll work on the rspec and see if I'm able to add the proxy options as well and ask for a review once I'm done. |
@rorra The You could create a private method, something like If you have question or need any tip, just let us know! |
released with version 2.1.0. |
If I'm right, on Savon, to create a connection with timeout options, you do something like
but on em-httprequest (version 1.0.3), the class HttpConnectionOptions, which has a constructor where it expects the uri and the options, never gets the options (which if I'm right, should be :connect_timeout and :inactivity_timeout).
later when I call an operation, with:
on Savon::Operation.call! the request is created by using HTTPI, and when it tries to do the request, on:
HTTPI::request, the line of code:
loads the adapter HTTPI::Adapter::EmHttpRequest
but when I check the adapter connection, I get:
so you can see that the connection_timeout is 5, and the inactivity_timeout is 10, and the HTTPI::Request that is used to build the EventMachine::HttpConnection is:
in few words, I cannot use timeout options with em-httprequest
The text was updated successfully, but these errors were encountered: