-module(gleam@http@service). -compile(no_auto_import). -export([map_response_body/2, prepend_response_header/3, method_override/1]). -spec map_response_body( fun((gleam@http@request:request(FCJ)) -> gleam@http@response:response(FCK)), fun((FCK) -> FCN) ) -> fun((gleam@http@request:request(FCJ)) -> gleam@http@response:response(FCN)). map_response_body(Service, Mapper) -> fun(Req) -> _pipe = Req, _pipe@1 = Service(_pipe), gleam@http@response:map(_pipe@1, Mapper) end. -spec prepend_response_header( fun((gleam@http@request:request(FCQ)) -> gleam@http@response:response(FCR)), binary(), binary() ) -> fun((gleam@http@request:request(FCQ)) -> gleam@http@response:response(FCR)). prepend_response_header(Service, Key, Value) -> fun(Req) -> _pipe = Req, _pipe@1 = Service(_pipe), gleam@http@response:prepend_header(_pipe@1, Key, Value) end. -spec ensure_post(gleam@http@request:request(FCW)) -> {ok, gleam@http@request:request(FCW)} | {error, nil}. ensure_post(Req) -> case erlang:element(2, Req) of post -> {ok, Req}; _@1 -> {error, nil} end. -spec get_override_method(gleam@http@request:request(any())) -> {ok, gleam@http:method()} | {error, nil}. get_override_method(Request) -> case gleam@http@request:get_query(Request) of {error, _try} -> {error, _try}; {ok, Query_params} -> case gleam@list:key_find(Query_params, <<"_method"/utf8>>) of {error, _try@1} -> {error, _try@1}; {ok, Method} -> case gleam@http:parse_method(Method) of {error, _try@2} -> {error, _try@2}; {ok, Method@1} -> case Method@1 of put -> {ok, Method@1}; patch -> {ok, Method@1}; delete -> {ok, Method@1}; _@1 -> {error, nil} end end end end. -spec method_override( fun((gleam@http@request:request(FDD)) -> gleam@http@response:response(FDE)) ) -> fun((gleam@http@request:request(FDD)) -> gleam@http@response:response(FDE)). method_override(Service) -> fun(Request) -> _pipe = Request, _pipe@1 = ensure_post(_pipe), _pipe@2 = gleam@result:then(_pipe@1, fun get_override_method/1), _pipe@3 = gleam@result:map( _pipe@2, fun(_capture) -> gleam@http@request:set_method(Request, _capture) end ), _pipe@4 = gleam@result:unwrap(_pipe@3, Request), Service(_pipe@4) end.