aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets
diff options
context:
space:
mode:
authorFredrik Gustafsson <fredrik@erlang.org>2013-03-13 13:57:42 +0100
committerFredrik Gustafsson <fredrik@erlang.org>2013-03-13 13:57:42 +0100
commit9285e0f558b1f39a241431e46691841bc0284d57 (patch)
tree15c698f69ef884f6ae5c3d968ed4d81cb385cfc4 /lib/inets
parent09fa1ba9b2f4becf68912bcfc4692d226344d920 (diff)
parent1932aa2bf42bdee119c9a7b9e1a7a1a7e627be15 (diff)
downloadotp-9285e0f558b1f39a241431e46691841bc0284d57.tar.gz
otp-9285e0f558b1f39a241431e46691841bc0284d57.tar.bz2
otp-9285e0f558b1f39a241431e46691841bc0284d57.zip
Merge branch 'cm/bug-http-content-length-zero/OTP-10934' into maint
* cm/bug-http-content-length-zero/OTP-10934: Fix http_request:http_headers/1 to send content-length when length is zero
Diffstat (limited to 'lib/inets')
-rw-r--r--lib/inets/src/http_lib/http_request.erl9
-rw-r--r--lib/inets/test/http_format_SUITE.erl24
2 files changed, 24 insertions, 9 deletions
diff --git a/lib/inets/src/http_lib/http_request.erl b/lib/inets/src/http_lib/http_request.erl
index c214aca4a4..fbfbe7c632 100644
--- a/lib/inets/src/http_lib/http_request.erl
+++ b/lib/inets/src/http_lib/http_request.erl
@@ -248,13 +248,8 @@ key_value_str(Key = 'content-language', Headers) ->
key_value_str(atom_to_list(Key),
Headers#http_request_h.'content-language');
key_value_str(Key = 'content-length', Headers) ->
- case Headers#http_request_h.'content-length' of
- "0" ->
- undefined;
- _ ->
- key_value_str(atom_to_list(Key),
- Headers#http_request_h.'content-length')
- end;
+ key_value_str(atom_to_list(Key),
+ Headers#http_request_h.'content-length');
key_value_str(Key = 'content-location', Headers) ->
key_value_str(atom_to_list(Key),
Headers#http_request_h.'content-location');
diff --git a/lib/inets/test/http_format_SUITE.erl b/lib/inets/test/http_format_SUITE.erl
index 04c7358715..c913964094 100644
--- a/lib/inets/test/http_format_SUITE.erl
+++ b/lib/inets/test/http_format_SUITE.erl
@@ -35,14 +35,15 @@
chunk_decode_trailer/1,
http_response/1, http_request/1, validate_request_line/1,
esi_parse_headers/1, cgi_parse_headers/1,
- is_absolut_uri/1, convert_netscapecookie_date/1]).
+ is_absolut_uri/1, convert_netscapecookie_date/1,
+ check_content_length_encoding/1]).
suite() -> [{ct_hooks,[ts_install_cth]}].
all() ->
[{group, chunk}, http_response, http_request,
validate_request_line, {group, script}, is_absolut_uri,
- convert_netscapecookie_date].
+ convert_netscapecookie_date, check_content_length_encoding].
groups() ->
[{script, [], [esi_parse_headers, cgi_parse_headers]},
@@ -456,6 +457,25 @@ validate_request_line(Config) when is_list(Config) ->
httpd_request:validate("GET", NewForbiddenUri1, "HTTP/1.1"),
ok.
+
+%%-------------------------------------------------------------------------
+check_content_length_encoding(doc) ->
+ ["Test http_request:headers/2. Check that the content-length is"
+ " encoded even when it is zero." ];
+check_content_length_encoding(suite) ->
+ [];
+check_content_length_encoding(Config) when is_list(Config) ->
+
+ %% Check that the content-length is preserved.
+ %% Sanity check.
+ Header1 = http_request:http_headers(#http_request_h{'content-length'="123"}),
+ true = (string:str(Header1, "content-length: 123\r\n") > 0),
+ %% Check that content-length=0 is handled correctly.
+ Header2 = http_request:http_headers(#http_request_h{'content-length'="0"}),
+ true = (string:str(Header2, "content-length: 0\r\n") > 0),
+
+ ok.
+
%%-------------------------------------------------------------------------
esi_parse_headers(doc) ->
["Test httpd_esi:*. All header values are received in the same"