···305 HttpResponse(202, [], Empty)
306}
30700000000000000000000000000000000308/// Create an empty response with status code 204: No content.
309///
310/// # Examples
···305 HttpResponse(202, [], Empty)
306}
307308+/// Create an empty response with status code 303: See Other, and the `location`
309+/// header set to the given URL. Used to redirect the client to another page.
310+///
311+/// # Examples
312+///
313+/// ```gleam
314+/// redirect(to: "https://example.com")
315+/// // -> Response(303, [#("location", "https://example.com")], Empty)
316+/// ```
317+///
318+pub fn redirect(to url: String) -> Response {
319+ HttpResponse(303, [#("location", url)], Empty)
320+}
321+322+/// Create an empty response with status code 308: Moved Permanently, and the
323+/// `location` header set to the given URL. Used to redirect the client to
324+/// another page.
325+///
326+/// This redirect is permanent and the client is expected to cache the new
327+/// location, using it for future requests.
328+///
329+/// # Examples
330+///
331+/// ```gleam
332+/// moved_permanently(to: "https://example.com")
333+/// // -> Response(308, [#("location", "https://example.com")], Empty)
334+/// ```
335+///
336+pub fn moved_permanently(to url: String) -> Response {
337+ HttpResponse(308, [#("location", url)], Empty)
338+}
339+340/// Create an empty response with status code 204: No content.
341///
342/// # Examples
+19
test/wisp_test.gleam
···32 |> should.equal(Response(204, [], wisp.Empty))
33}
3400000000000000000035pub fn internal_server_error_test() {
36 wisp.internal_server_error()
37 |> should.equal(Response(500, [], wisp.Empty))
···245}
246247pub fn rescue_crashes_error_test() {
0248 {
249 use <- wisp.rescue_crashes
250 panic as "we need to crash to test the middleware"
···32 |> should.equal(Response(204, [], wisp.Empty))
33}
3435+pub fn redirect_test() {
36+ wisp.redirect(to: "https://example.com/wibble")
37+ |> should.equal(Response(
38+ 303,
39+ [#("location", "https://example.com/wibble")],
40+ wisp.Empty,
41+ ))
42+}
43+44+pub fn moved_permanently_test() {
45+ wisp.moved_permanently(to: "https://example.com/wobble")
46+ |> should.equal(Response(
47+ 308,
48+ [#("location", "https://example.com/wobble")],
49+ wisp.Empty,
50+ ))
51+}
52+53pub fn internal_server_error_test() {
54 wisp.internal_server_error()
55 |> should.equal(Response(500, [], wisp.Empty))
···263}
264265pub fn rescue_crashes_error_test() {
266+ // TODO: Determine how to silence the logger for this test.
267 {
268 use <- wisp.rescue_crashes
269 panic as "we need to crash to test the middleware"