if the option return_raw_request` was unset or false, ibrowse was
still returning the returning thhe raw request. This change fix it.
(Spotted while running couchdb tests)
fix function_clause error:
{error,
{error,
{'EXIT',
{{function_clause,
[{ibrowse_http_client,do_send_body_1,
[{{ok,<<>>},
The case {Function, State} wasn't took in consideration while handling
the body.
Below are the warnings that were fixed by this commit.
[git: master]Iris:ibrowse andreas$ make dialyzer
Building local plt at .dialyzer_plt
dialyzer --output_plt .dialyzer_plt --build_plt \
--apps erts kernel stdlib ssl crypto public_key asn1 compiler hipe edoc gs syntax_tools inets xmerl runtime_tools mnesia
Compiling some key modules to native code... done in 0m19.73s
Creating PLT .dialyzer_plt ... done in 1m40.98s
done (passed successfully)
dialyzer --fullpath --plt .dialyzer_plt -Wrace_conditions -Wunmatched_returns -Werror_handling -r ./ebin
Checking whether the PLT .dialyzer_plt is up-to-date... yes
Proceeding with analysis...
src/ibrowse_http_client.erl:197: Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched
src/ibrowse_http_client.erl:298: Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched
src/ibrowse_http_client.erl:322: Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched
src/ibrowse_http_client.erl:335: Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched
src/ibrowse_http_client.erl:352: Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched
src/ibrowse_http_client.erl:582: Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched
src/ibrowse_http_client.erl:587: Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched
src/ibrowse_http_client.erl:590: Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched
src/ibrowse_http_client.erl:706: Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched
src/ibrowse_http_client.erl:789: Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched
src/ibrowse_http_client.erl:797: Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched
src/ibrowse_http_client.erl:1402: Expression produces a value of type 'ok' | {'error',_}, but this value is unmatched
src/ibrowse_http_client.erl:1859: Expression produces a value of type 'ok' | integer(), but this value is unmatched
src/ibrowse_socks5.erl:25: Expression produces a value of type {'ok',<<_:16>>}, but this value is unmatched
done in 0m8.07s
done (warnings were emitted)
make: *** [dialyzer] Error 2
When a tcp_closed or ssl_closed message is handled while ibrowse is
trying to send a request to a worker, ibrowse would incorrectly return a
req_timedout message, when, in fact, the request had not even been
handled.
This patch attempts to avoid that race condition by signalling tcp or
ssl closed messages back to ibrowse differently than a normal exit.
Like in synchronous programming, in makes sense to start an inactivity timer only when the caller
does a "recv" call and cancel the timer as soon as data is received from the socket.
This avoids plenty of connection inactivity timeouts. From a logical point of view,
the inactivity timeout should be reset not only only data is received from the socket
but also when the client asks for more data.
Currently ibrowse defined the nodelay socket option to true, not allowing the caller
to supply its own value, which would also make the sndbuf option useless if the caller
supplied it as well.
When sending large bodies, setting nodelay to false with a custom sndbuf can improve
network throughput very significantly. For e.g., custom tests reduced an upload from
16 minutes to about 12 minutes.
Allow chunks to be IO lists. These lists will get flattened by the ERTS in
a much more efficient way than converting them to raw binaries in Erlang code.
When reusing the same connection (ibrowse worker) for multiple requests, the current
inactivity timeout must be cleared before sending a request body. When the sending of the
body takes more than inactivity_timeout milliseconds, the client will get
a req_timedout error. Currenty inactivity_timer is cleared only after sending the whole body.
1) Set Content-Length to 0 for empty PUT and POST requests (necessary for some proxies);
2) Use iolist_size/1 instead of size/1 or length/1 because the body can be an iolist