nickva commented on code in PR #6098:
URL: https://github.com/apache/couchdb/pull/6098#discussion_r3839957048


##########
src/couch/src/test_request.erl:
##########
@@ -86,25 +88,101 @@ request(Method, Url, Headers, Body, Opts) ->
 request(_Method, _Url, _Headers, _Body, _Opts, 0) ->
     {error, request_failed};
 request(Method, Url, Headers, Body, Opts, N) ->
-    case code:is_loaded(ibrowse) of
-        false ->
-            {ok, _} = ibrowse:start();
-        _ ->
-            ok
-    end,
-    case ibrowse:send_req(Url, Headers, Method, Body, Opts) of
-        {ok, Code0, RespHeaders, RespBody0} ->
-            Code = list_to_integer(Code0),
-            RespBody = iolist_to_binary(RespBody0),
-            {ok, Code, RespHeaders, RespBody};
-        {error, {'EXIT', {normal, _}}} ->
-            % Connection closed right after a successful request that
-            % used the same connection.
-            request(Method, Url, Headers, Body, Opts, N - 1);
-        {error, retry_later} ->
-            % CouchDB is busy, let’s wait a bit
-            timer:sleep(3000 div N),
+    {ok, _} = application:ensure_all_started(gun),
+    Headers1 = headers(Headers, Opts),
+    ReqOpts = #{timeout => ?TIMEOUT, tls_opts => [{verify, verify_none}]},
+    case couch_gun:req(Method, Url, Headers1, Body, ReqOpts) of
+        {ok, Code, RespHeaders, RespBody} ->
+            {ok, Code, canonical_headers(RespHeaders), RespBody};
+        {error, closed} ->
+            % Retry. Possible race with the server starting.
             request(Method, Url, Headers, Body, Opts, N - 1);
         Error ->
             Error
     end.
+
+headers(Headers, Opts) ->
+    lists:foldl(fun apply_opt/2, couch_gun:headers(Headers), Opts).
+
+apply_opt({host_header, Value}, Headers) ->
+    [Host] = couch_gun:headers([{host, Value}]),
+    lists:keystore(~"host", 1, Headers, Host);
+apply_opt({basic_auth, {User, Pass}}, Headers) ->
+    Auth = couch_gun:basic_auth(User, Pass),
+    lists:keystore(~"authorization", 1, Headers, Auth);
+apply_opt(_Other, Headers) ->
+    Headers.
+
+% Gun returns headers as lower case we we update them to camel case to avoid

Review Comment:
   Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to