Skip to content

Commit

Permalink
add body constructor function for testing handlers
Browse files Browse the repository at this point in the history
fixes #16
  • Loading branch information
rawhat committed Jun 13, 2023
1 parent 2ce0076 commit 5ae230c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/mist/internal/http.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ pub opaque type Body {
Read(data: BitString)
}

/// This function exists purely for unit testing handlers. It allows you to
/// create a `Request(Body)` which is required by `handler_func`.
pub fn static_body(data: BitString) -> Body {
Read(data)
}

pub fn read_body(req: Request(Body)) -> Result(Request(BitString), DecodeError) {
let transport = case req.scheme {
http.Https -> transport.ssl()
Expand Down

0 comments on commit 5ae230c

Please sign in to comment.