Current section
Files
Jump to
Current section
Files
src/glitch@extended@uri_ext.erl
-module(glitch@extended@uri_ext).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([path_from_segments/1, host_from_string/1, set_host/2, set_scheme/2, set_path/2, set_port/2, set_query/2, new/0]).
-spec path_from_segments(list(binary())) -> {ok, gleam@uri:uri()} | {error, nil}.
path_from_segments(Segments) ->
_pipe = Segments,
_pipe@1 = gleam@list:map(
_pipe,
fun(_capture) ->
gleam@string:replace(_capture, <<"/"/utf8>>, <<""/utf8>>)
end
),
_pipe@2 = gleam@string:join(_pipe@1, <<"/"/utf8>>),
gleam@uri:parse(_pipe@2).
-spec host_from_string(binary()) -> {ok, gleam@uri:uri()} | {error, nil}.
host_from_string(Host_str) ->
gleam@uri:parse(Host_str).
-spec set_host(gleam@uri:uri(), gleam@uri:uri()) -> gleam@uri:uri().
set_host(Uri, Host) ->
erlang:setelement(4, Uri, erlang:element(4, Host)).
-spec set_scheme(gleam@uri:uri(), gleam@http:scheme()) -> gleam@uri:uri().
set_scheme(Uri, Scheme) ->
erlang:setelement(2, Uri, {some, gleam@http:scheme_to_string(Scheme)}).
-spec set_path(gleam@uri:uri(), gleam@uri:uri()) -> gleam@uri:uri().
set_path(Uri, Path) ->
erlang:setelement(6, Uri, erlang:element(6, Path)).
-spec set_port(gleam@uri:uri(), integer()) -> gleam@uri:uri().
set_port(Uri, Port) ->
erlang:setelement(5, Uri, {some, Port}).
-spec set_query(gleam@uri:uri(), list({binary(), binary()})) -> gleam@uri:uri().
set_query(Uri, Query_params) ->
Query = begin
_pipe = Query_params,
_pipe@1 = gleam@uri:query_to_string(_pipe),
{some, _pipe@1}
end,
erlang:setelement(7, Uri, Query).
-spec new() -> gleam@uri:uri().
new() ->
{uri, none, none, none, none, <<""/utf8>>, none, none}.