File 3251-inets-add-PATCH-method-support.patch of Package erlang

From 98fe91d529487a976952f3b7411b4d6e7c260e38 Mon Sep 17 00:00:00 2001
From: Ao Song <andy@erlang.org>
Date: Wed, 24 Jun 2020 14:51:46 +0200
Subject: [PATCH] inets: add PATCH method support

Change-Id: Icbb324e602efb3832fffc4a650ce99989cd01ac8
---
 lib/inets/src/http_server/httpd_example.erl | 13 ++++++++++++-
 lib/inets/src/http_server/mod_esi.erl       | 15 ++++-----------
 lib/inets/test/httpd_SUITE.erl              | 11 ++++++++++-
 3 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/lib/inets/src/http_server/httpd_example.erl b/lib/inets/src/http_server/httpd_example.erl
index 78b781aa96..bb048e2410 100644
--- a/lib/inets/src/http_server/httpd_example.erl
+++ b/lib/inets/src/http_server/httpd_example.erl
@@ -22,7 +22,8 @@
 
 -export([print/3, 
          get/3, 
-         put/3, 
+         put/3,
+         patch/3,
          post/3, 
          yahoo/3, 
          test1/3, 
@@ -84,6 +85,16 @@ do_put(Env,{Input,_Body}) ->
     default(Env,Input);
 do_put(Env,Input) ->
     default(Env,Input).
+
+%% ------------------------------------------------------
+patch(SessionID, Env, Input) ->
+    mod_esi:deliver(SessionID, do_patch(Env, Input)).
+
+do_patch(Env,{Input,_Body}) ->
+    default(Env,Input);
+do_patch(Env,Input) ->
+    default(Env,Input).
+
 %% ------------------------------------------------------
 get_bin(SessionID, Env, Input) ->
     Header = header(),
diff --git a/lib/inets/src/http_server/mod_esi.erl b/lib/inets/src/http_server/mod_esi.erl
index 00268aefec..3da503a5f2 100644
--- a/lib/inets/src/http_server/mod_esi.erl
+++ b/lib/inets/src/http_server/mod_esi.erl
@@ -186,8 +186,9 @@ erl(#mod{method = Method} = ModData, ESIBody, Modules)
 	    {proceed, [{status,{400, none, BadRequest}} | ModData#mod.data]}
     end;
 
-erl(#mod{method = "PUT", entity_body = Body} = ModData,
-    ESIBody, Modules) ->
+erl(#mod{method = Method, entity_body = Body} = ModData,
+    ESIBody, Modules) when Method =:= "PUT" orelse
+                           Method =:= "PATCH" ->
     case httpd_util:split(ESIBody,":|%3A|/",2) of
 	{ok, [ModuleName, FuncAndInput]} ->                
 	    case httpd_util:split(FuncAndInput,"[\?/]",2) of
@@ -217,15 +218,7 @@ erl(#mod{method = "POST", entity_body = Body} = ModData, ESIBody, Modules) ->
 			     Function, Body, []);
 	{ok, BadRequest} ->
 	    {proceed,[{status, {400, none, BadRequest}} | ModData#mod.data]}
-    end;
-
-erl(#mod{request_uri  = ReqUri, 
-	 method       = "PATCH",
-         http_version = Version, 
-	 data         = Data}, _ESIBody, _Modules) ->
-    {proceed, [{status,{501,{"PATCH", ReqUri, Version},
-			?NICE("Erl mechanism doesn't support method PATCH")}}|
-	       Data]}.
+    end.
 
 generate_webpage(ModData, ESIBody, [all], Module, FunctionName,
 		 Input, ScriptElements) ->
diff --git a/lib/inets/test/httpd_SUITE.erl b/lib/inets/test/httpd_SUITE.erl
index 3615967469..e4efeb1b81 100644
--- a/lib/inets/test/httpd_SUITE.erl
+++ b/lib/inets/test/httpd_SUITE.erl
@@ -132,7 +132,7 @@ groups() ->
      {http_1_1, [],
       [host, chunked, expect, cgi, cgi_chunked_encoding_test,
        trace, range, if_modified_since, mod_esi_chunk_timeout,
-       esi_put, esi_post, esi_proagate, esi_atom_leak] ++ http_head() ++ http_get() ++ load()},
+       esi_put, esi_patch, esi_post, esi_proagate, esi_atom_leak] ++ http_head() ++ http_get() ++ load()},
      {http_1_0, [], [host, cgi, trace] ++ http_head() ++ http_get() ++ load()},
      {http_rel_path_script_alias, [], [cgi]},
      {not_sup, [], [put_not_sup]}
@@ -866,6 +866,15 @@ esi_put() ->
 esi_put(Config) when is_list(Config) ->
     ok = http_status("PUT /cgi-bin/erl/httpd_example/put/123342234123 ",
 		     Config, [{statuscode, 200}]).
+
+%%-------------------------------------------------------------------------
+esi_patch() ->
+    [{doc, "Test mod_esi PATCH"}].
+
+esi_patch(Config) when is_list(Config) ->
+    ok = http_status("PATCH /cgi-bin/erl/httpd_example/patch/1234567890 ",
+		     Config, [{statuscode, 200}]).
+
 %%-------------------------------------------------------------------------
 esi_post() ->
     [{doc, "Test mod_esi POST"}].
-- 
2.26.2

openSUSE Build Service is sponsored by