Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:19
erlang
0465-inets-Fix-handling-of-Content-Type-httpc.p...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0465-inets-Fix-handling-of-Content-Type-httpc.patch of Package erlang
From d95cfc3b4a8ea1bbd8ad6c90f1e00b0150a87d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Dimitrov?= <peterdmv@erlang.org> Date: Tue, 2 Oct 2018 17:03:00 +0200 Subject: [PATCH] inets: Fix handling of 'Content-Type' (httpc) 'Content-Type' is sent when it is explicitly set as a header or there is a non-empty body in the request. Former implementation dropped the explicit 'Content-Type' when the request had an empty body. Change-Id: I00a9e4a5011f9d28c04c0dfc5fe1561b1ab7eb09 --- lib/inets/src/http_client/httpc_request.erl | 12 ++++++++++-- lib/inets/test/httpc_SUITE.erl | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/inets/src/http_client/httpc_request.erl b/lib/inets/src/http_client/httpc_request.erl index 9b81bd7a80..4cb2d57b14 100644 --- a/lib/inets/src/http_client/httpc_request.erl +++ b/lib/inets/src/http_client/httpc_request.erl @@ -213,9 +213,11 @@ update_body(Headers, Body) -> update_headers(Headers, ContentType, Body, []) -> case Body of [] -> - Headers#http_request_h{'content-length' = "0"}; + Headers1 = Headers#http_request_h{'content-length' = "0"}, + handle_content_type(Headers1, ContentType); <<>> -> - Headers#http_request_h{'content-length' = "0"}; + Headers1 = Headers#http_request_h{'content-length' = "0"}, + handle_content_type(Headers1, ContentType); {Fun, _Acc} when is_function(Fun, 1) -> %% A client MUST NOT generate a 100-continue expectation in a request %% that does not include a message body. This implies that either the @@ -245,6 +247,12 @@ body_length(Body) when is_binary(Body) -> body_length(Body) when is_list(Body) -> integer_to_list(length(Body)). +%% Set 'Content-Type' when it is explicitly set. +handle_content_type(Headers, "") -> + Headers; +handle_content_type(Headers, ContentType) -> + Headers#http_request_h{'content-type' = ContentType}. + method(Method) -> http_util:to_upper(atom_to_list(Method)). diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index 3d375222b5..89a90b62f3 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -128,6 +128,7 @@ only_simulated() -> port_in_host_header, redirect_port_in_host_header, relaxed, + post_with_content_type, multipart_chunks ]. @@ -1133,6 +1134,15 @@ delete_no_body(Config) when is_list(Config) -> {ok, {{_, 200, _}, _, Body}} = httpc:request(get, Request, [], []), inets_test_lib:check_body(Body). +%%-------------------------------------------------------------------- +post_with_content_type(doc) -> + ["Test that a POST request with explicit 'Content-Type' does not drop the 'Content-Type' header - Solves ERL-736"]; +post_with_content_type(Config) when is_list(Config) -> + URL = url(group_name(Config), "/delete_no_body.html", Config), + %% Simulated server replies 500 if 'Content-Type' header is present + {ok, {{_,500,_}, _, _}} = + httpc:request(post, {URL, [], "application/x-www-form-urlencoded", ""}, [], []). + %%------------------------------------------------------------------------- multipart_chunks(Config) when is_list(Config) -> Request = {url(group_name(Config), "/multipart_chunks.html", Config), []}, -- 2.16.4
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor