Skip to content

Commit

Permalink
Merge pull request #63 from robur-coop/content-length
Browse files Browse the repository at this point in the history
Middleware: respond with content-length
  • Loading branch information
PizieDust authored Oct 11, 2024
2 parents faa9dbb + 5648bb0 commit 187c3e1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions middleware.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let redirect_to_login reqd ?(msg = "") () =
"molly_session=;Path=/;HttpOnly=true;Expires=2023-10-27T11:00:00.778Z"
);
("location", "/sign-in");
("Content-Length", string_of_int (String.length msg));
]
in
let headers = Httpaf.Headers.of_list header_list in
Expand All @@ -39,6 +40,7 @@ let redirect_to_register reqd ?(msg = "") () =
"molly_session=;Path=/;HttpOnly=true;Expires=2023-10-27T11:00:00.778Z"
);
("location", "/sign-up");
("Content-Length", string_of_int (String.length msg));
]
in
let headers = Httpaf.Headers.of_list header_list in
Expand Down Expand Up @@ -67,13 +69,25 @@ let redirect_to_error ~title ~data status user code api_meth reqd () =
Httpaf.Reqd.respond_with_string reqd resp data)

let redirect_to_verify_email reqd ?(msg = "") () =
let headers = Httpaf.Headers.of_list [ ("location", "/verify-email") ] in
let headers =
Httpaf.Headers.of_list
[
("location", "/verify-email");
("Content-Length", string_of_int (String.length msg));
]
in
let response = Httpaf.Response.create ~headers `Found in
Httpaf.Reqd.respond_with_string reqd response msg;
Lwt.return_unit

let redirect_to_dashboard reqd ?(msg = "") () =
let headers = Httpaf.Headers.of_list [ ("location", "/dashboard") ] in
let headers =
Httpaf.Headers.of_list
[
("location", "/dashboard");
("Content-Length", string_of_int (String.length msg));
]
in
let response = Httpaf.Response.create ~headers `Found in
Httpaf.Reqd.respond_with_string reqd response msg;
Lwt.return_unit
Expand Down

0 comments on commit 187c3e1

Please sign in to comment.