Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
1314-inets-httpc-enhance-error-handling.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 1314-inets-httpc-enhance-error-handling.patch of Package erlang
From 9428354b7bfac337ffbdd7a58304adae8bb3f2d1 Mon Sep 17 00:00:00 2001 From: Ingela Anderton Andin <ingela@erlang.org> Date: Tue, 1 Aug 2023 09:22:07 +0200 Subject: [PATCH] inets: httpc - enhance error handling closes #7482 --- lib/inets/src/http_client/httpc_request.erl | 28 +++++++++++++-------- lib/inets/src/http_lib/http_request.erl | 11 ++++++-- lib/inets/test/httpc_SUITE.erl | 13 ++++++++-- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lib/inets/src/http_client/httpc_request.erl b/lib/inets/src/http_client/httpc_request.erl index 861bb5d683..8335c26347 100644 --- a/lib/inets/src/http_client/httpc_request.erl +++ b/lib/inets/src/http_client/httpc_request.erl @@ -95,17 +95,23 @@ send(SendAddr, Socket, SocketType, {TmpHdrs2, Path ++ Query} end, - FinalHeaders = - case NewHeaders of - HeaderList when is_list(HeaderList) -> - http_headers(HeaderList, []); - _ -> - http_request:http_headers(NewHeaders) - end, - Version = HttpOptions#http_options.version, - - do_send_body(SocketType, Socket, Method, Uri, Version, FinalHeaders, Body). - + FinalHeaders = try + case NewHeaders of + HeaderList when is_list(HeaderList) -> + http_headers(HeaderList, []); + _ -> + http_request:http_headers(NewHeaders) + end + catch throw:{invalid_header, _} = Bad -> + {error, Bad} + end, + case FinalHeaders of + {error,_} = InvalidHeaders -> + InvalidHeaders; + _ -> + Version = HttpOptions#http_options.version, + do_send_body(SocketType, Socket, Method, Uri, Version, FinalHeaders, Body) + end. do_send_body(SocketType, Socket, Method, Uri, Version, Headers, {ProcessBody, Acc}) when is_function(ProcessBody, 1) -> diff --git a/lib/inets/src/http_lib/http_request.erl b/lib/inets/src/http_lib/http_request.erl index af8b6754b1..4eef100b95 100644 --- a/lib/inets/src/http_lib/http_request.erl +++ b/lib/inets/src/http_lib/http_request.erl @@ -201,7 +201,8 @@ headers(Key, Value, Headers) -> key_value_str(Key, Headers) -> case key_value(Key, Headers) of - undefined -> undefined; + undefined -> + undefined; Value -> mk_key_value_str(atom_to_list(Key), Value) end. @@ -289,7 +290,13 @@ headers_other([{Key, Value} | Rest], Headers) -> headers_other(Rest, [mk_key_value_str(Key, Value) | Headers]). mk_key_value_str(Key, Value) -> - Key ++ ": " ++ value_to_list(Value) ++ ?CRLF. + try Key ++ ": " ++ value_to_list(Value) ++ ?CRLF of + HeaderStr -> + HeaderStr + catch + error:_ -> + throw({invalid_header, {Key, Value}}) + end. value_to_list(Binary) when is_binary(Binary) -> binary_to_list(Binary); diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index f89b06fddd..cfbe02363d 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -98,7 +98,6 @@ real_requests()-> persistent_connection, save_to_file, save_to_file_async, - headers_as_is, page_does_not_exist, emulate_lower_versions, headers, @@ -134,6 +133,7 @@ real_requests()-> stream_through_mfa, streaming_error, inet_opts, + invalid_headers, invalid_headers_key, invalid_headers_value, invalid_body, @@ -1281,8 +1282,16 @@ headers_conflict_chunked_with_length(Config) when is_list(Config) -> ok. %%------------------------------------------------------------------------- +invalid_headers(doc) -> + ["Test invalid header format"]; +invalid_headers(Config) when is_list(Config) -> + URL = url(group_name(Config), "/dummy.html", Config), + {error,{invalid_header,{"headers", + [{"user-agent","httpc"}]}}} = + httpc:request(get, {URL, [{"headers", [{"user-agent", "httpc"}]}]}, + [?SSL_NO_VERIFY], []). - +%%------------------------------------------------------------------------- invalid_headers_key(Config) -> Request = {url(group_name(Config), "/dummy.html", Config), [{cookie, "valid cookie"}]}, -- 2.35.3
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