From 112cf5843a52fa6a57865faea5b7e60ec1a7e141 Mon Sep 17 00:00:00 2001 From: DataTriny Date: Tue, 4 Oct 2022 22:25:41 +0200 Subject: inets: Implement HTTP 308 Permanent Redirect --- lib/inets/test/httpc_SUITE.erl | 36 ++++++++++++++++++++++++++++++++++++ lib/inets/test/httpd_poll.erl | 1 + lib/inets/test/httpd_time_test.erl | 1 + 3 files changed, 38 insertions(+) (limited to 'lib/inets/test') diff --git a/lib/inets/test/httpc_SUITE.erl b/lib/inets/test/httpc_SUITE.erl index 1c1e642714..32dbf6b97b 100644 --- a/lib/inets/test/httpc_SUITE.erl +++ b/lib/inets/test/httpc_SUITE.erl @@ -181,6 +181,7 @@ only_simulated() -> redirect_found, redirect_see_other, redirect_temporary_redirect, + redirect_permanent_redirect, redirect_relative_uri, port_in_host_header, redirect_port_in_host_header, @@ -758,6 +759,26 @@ redirect_temporary_redirect(Config) when is_list(Config) -> = httpc:request(post, {URL307, [],"text/plain", "foobar"}, [], []). %%------------------------------------------------------------------------- +redirect_permanent_redirect() -> + [{doc, "The server SHOULD generate a Location header field in the response " + "containing a preferred URI reference for the new permanent URI. " + "The user agent MAY use the Location field value for automatic redirection. " + "The server's response content usually contains a short hypertext note with " + "a hyperlink to the new URI(s)."}]. +redirect_permanent_redirect(Config) when is_list(Config) -> + + URL308 = url(group_name(Config), "/308.html", Config), + + {ok, {{_,200,_}, [_ | _], [_|_]}} + = httpc:request(get, {URL308, []}, [], []), + + {ok, {{_,200,_}, [_ | _], []}} + = httpc:request(head, {URL308, []}, [], []), + + {ok, {{_,200,_}, [_ | _], [_|_]}} + = httpc:request(post, {URL308, [],"text/plain", "foobar"}, + [], []). +%%------------------------------------------------------------------------- redirect_relative_uri() -> [{doc, "The server SHOULD generate a Location header field in the response " "containing a preferred URI reference for the new permanent URI. The user " @@ -2601,6 +2622,21 @@ handle_uri(_,"/307.html",Port,_,Socket,_) -> "Location:" ++ NewUri ++ "\r\n" ++ "Content-Length:" ++ integer_to_list(length(Body)) ++ "\r\n\r\n" ++ Body; +handle_uri("HEAD","/308.html",Port,_,Socket,_) -> + NewUri = url_start(Socket) ++ + integer_to_list(Port) ++ "/dummy.html", + "HTTP/1.1 308 Permanent Redirect \r\n" ++ + "Location:" ++ NewUri ++ "\r\n" ++ + "Content-Length:0\r\n\r\n"; +handle_uri(_,"/308.html",Port,_,Socket,_) -> + NewUri = url_start(Socket) ++ + integer_to_list(Port) ++ "/dummy.html", + Body = "New place", + "HTTP/1.1 308 Permanent Redirect \r\n" ++ + "Location:" ++ NewUri ++ "\r\n" ++ + "Content-Length:" ++ integer_to_list(length(Body)) + ++ "\r\n\r\n" ++ Body; handle_uri(_,"/404.html",_,_,_,_) -> "HTTP/1.1 404 not found\r\n" ++ diff --git a/lib/inets/test/httpd_poll.erl b/lib/inets/test/httpd_poll.erl index f86e3a979b..d28a68c0c6 100644 --- a/lib/inets/test/httpd_poll.erl +++ b/lib/inets/test/httpd_poll.erl @@ -332,6 +332,7 @@ status_to_message(303) -> "Section 10.3.4: See Other"; status_to_message(304) -> "Section 10.3.5: Not Modified"; status_to_message(305) -> "Section 10.3.6: Use Proxy"; status_to_message(307) -> "Section 10.3.8: Temporary Redirect"; +status_to_message(308) -> "RFC 9110, Section 15.4.9: Permanent Redirect"; status_to_message(400) -> "Section 10.4.1: Bad Request"; status_to_message(401) -> "Section 10.4.2: Unauthorized"; status_to_message(402) -> "Section 10.4.3: Peyment Required"; diff --git a/lib/inets/test/httpd_time_test.erl b/lib/inets/test/httpd_time_test.erl index 87a913fce4..d00dc40e61 100644 --- a/lib/inets/test/httpd_time_test.erl +++ b/lib/inets/test/httpd_time_test.erl @@ -450,6 +450,7 @@ status_to_message(303) -> "Section 10.3.4: See Other"; status_to_message(304) -> "Section 10.3.5: Not Modified"; status_to_message(305) -> "Section 10.3.6: Use Proxy"; status_to_message(307) -> "Section 10.3.8: Temporary Redirect"; +status_to_message(308) -> "RFC 9110, Section 15.4.9: Permanent Redirect"; status_to_message(400) -> "Section 10.4.1: Bad Request"; status_to_message(401) -> "Section 10.4.2: Unauthorized"; status_to_message(402) -> "Section 10.4.3: Peyment Required"; -- cgit v1.2.1