Packages
A practical web framework for Gleam
Security advisory:
This version has known vulnerabilities.
View advisories
Current section
Files
Jump to
Current section
Files
src/wisp@testing.erl
-module(wisp@testing).
-compile([no_auto_import, nowarn_unused_vars]).
-export([request/4, get/2, post/3, head/2, put/3, delete/3, trace/2, connect/2, options/2, patch/3, string_body/1, bit_string_body/1]).
-spec request(
gleam@http:method(),
binary(),
list({binary(), binary()}),
bitstring()
) -> gleam@http@request:request(wisp:connection()).
request(Method, Path, Headers, Body) ->
_pipe = {request,
Method,
Headers,
Body,
https,
<<"localhost"/utf8>>,
none,
Path,
none},
gleam@http@request:set_body(
_pipe,
wisp:create_canned_connection(
Body,
<<"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/utf8>>
)
).
-spec get(binary(), list({binary(), binary()})) -> gleam@http@request:request(wisp:connection()).
get(Path, Headers) ->
request(get, Path, Headers, <<>>).
-spec post(binary(), list({binary(), binary()}), binary()) -> gleam@http@request:request(wisp:connection()).
post(Path, Headers, Body) ->
request(post, Path, Headers, <<Body/binary>>).
-spec head(binary(), list({binary(), binary()})) -> gleam@http@request:request(wisp:connection()).
head(Path, Headers) ->
request(head, Path, Headers, <<>>).
-spec put(binary(), list({binary(), binary()}), binary()) -> gleam@http@request:request(wisp:connection()).
put(Path, Headers, Body) ->
request(put, Path, Headers, <<Body/binary>>).
-spec delete(binary(), list({binary(), binary()}), binary()) -> gleam@http@request:request(wisp:connection()).
delete(Path, Headers, Body) ->
request(delete, Path, Headers, <<Body/binary>>).
-spec trace(binary(), list({binary(), binary()})) -> gleam@http@request:request(wisp:connection()).
trace(Path, Headers) ->
request(trace, Path, Headers, <<>>).
-spec connect(binary(), list({binary(), binary()})) -> gleam@http@request:request(wisp:connection()).
connect(Path, Headers) ->
request(connect, Path, Headers, <<>>).
-spec options(binary(), list({binary(), binary()})) -> gleam@http@request:request(wisp:connection()).
options(Path, Headers) ->
request(options, Path, Headers, <<>>).
-spec patch(binary(), list({binary(), binary()}), binary()) -> gleam@http@request:request(wisp:connection()).
patch(Path, Headers, Body) ->
request(patch, Path, Headers, <<Body/binary>>).
-spec string_body(gleam@http@response:response(wisp:body())) -> binary().
string_body(Response) ->
case erlang:element(4, Response) of
empty ->
<<""/utf8>>;
{text, Builder} ->
gleam@string_builder:to_string(Builder);
{file, Path} ->
_assert_subject = simplifile:read(Path),
{ok, Contents} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"wisp/testing"/utf8>>,
function => <<"string_body"/utf8>>,
line => 112})
end,
Contents
end.
-spec bit_string_body(gleam@http@response:response(wisp:body())) -> bitstring().
bit_string_body(Response) ->
case erlang:element(4, Response) of
empty ->
<<>>;
{text, Builder} ->
gleam@bit_builder:to_bit_string(
gleam@bit_builder:from_string_builder(Builder)
);
{file, Path} ->
_assert_subject = simplifile:read_bits(Path),
{ok, Contents} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"wisp/testing"/utf8>>,
function => <<"bit_string_body"/utf8>>,
line => 131})
end,
Contents
end.