aboutsummaryrefslogtreecommitdiff
path: root/aoc2023/build/packages/gleam_http/src/gleam@http@service.erl
diff options
context:
space:
mode:
authorHJ <thechairman@thechairman.info>2024-02-03 15:09:54 -0500
committerHJ <thechairman@thechairman.info>2024-02-03 15:09:54 -0500
commit96a3c5c179d8d3fff24eb2953e45f8dd15e2714c (patch)
tree0a67bc0cfeabe51740bb049c61f16f1ac3bdd4ff /aoc2023/build/packages/gleam_http/src/gleam@http@service.erl
parent547fe03cf43105f46160e2dd9afff21637eaaf47 (diff)
downloadgleam_aoc-96a3c5c179d8d3fff24eb2953e45f8dd15e2714c.tar.gz
gleam_aoc-96a3c5c179d8d3fff24eb2953e45f8dd15e2714c.zip
cleanup
Diffstat (limited to 'aoc2023/build/packages/gleam_http/src/gleam@http@service.erl')
-rw-r--r--aoc2023/build/packages/gleam_http/src/gleam@http@service.erl82
1 files changed, 82 insertions, 0 deletions
diff --git a/aoc2023/build/packages/gleam_http/src/gleam@http@service.erl b/aoc2023/build/packages/gleam_http/src/gleam@http@service.erl
new file mode 100644
index 0000000..d07b31f
--- /dev/null
+++ b/aoc2023/build/packages/gleam_http/src/gleam@http@service.erl
@@ -0,0 +1,82 @@
+-module(gleam@http@service).
+-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]).
+
+-export([map_response_body/2, prepend_response_header/3, method_override/1]).
+
+-spec map_response_body(
+ fun((gleam@http@request:request(GJL)) -> gleam@http@response:response(GJM)),
+ fun((GJM) -> GJP)
+) -> fun((gleam@http@request:request(GJL)) -> gleam@http@response:response(GJP)).
+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(GJS)) -> gleam@http@response:response(GJT)),
+ binary(),
+ binary()
+) -> fun((gleam@http@request:request(GJS)) -> gleam@http@response:response(GJT)).
+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(GJY)) -> {ok,
+ gleam@http@request:request(GJY)} |
+ {error, nil}.
+ensure_post(Req) ->
+ case erlang:element(2, Req) of
+ post ->
+ {ok, Req};
+
+ _ ->
+ {error, nil}
+ end.
+
+-spec get_override_method(gleam@http@request:request(any())) -> {ok,
+ gleam@http:method()} |
+ {error, nil}.
+get_override_method(Request) ->
+ gleam@result:then(
+ gleam@http@request:get_query(Request),
+ fun(Query_params) ->
+ gleam@result:then(
+ gleam@list:key_find(Query_params, <<"_method"/utf8>>),
+ fun(Method) ->
+ gleam@result:then(
+ gleam@http:parse_method(Method),
+ fun(Method@1) -> case Method@1 of
+ put ->
+ {ok, Method@1};
+
+ patch ->
+ {ok, Method@1};
+
+ delete ->
+ {ok, Method@1};
+
+ _ ->
+ {error, nil}
+ end end
+ )
+ end
+ )
+ end
+ ).
+
+-spec method_override(
+ fun((gleam@http@request:request(GKF)) -> gleam@http@response:response(GKG))
+) -> fun((gleam@http@request:request(GKF)) -> gleam@http@response:response(GKG)).
+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.