change redirect content type

This commit is contained in:
zapashcanon 2024-01-08 00:19:40 +01:00
parent f9ee533917
commit 531538cc3f
Signed by untrusted user who does not match committer: zapashcanon
GPG Key ID: 8981C3C62D1D28F1
3 changed files with 16 additions and 7 deletions

View File

@ -86,13 +86,16 @@ end = struct
let target = List.filter (fun s -> s <> "") target in
let target = Array.of_list target in
let response = handler target request in
let status, content =
let status, content, status_headers =
match response with
| Ok content -> (`OK, content)
| Ok content -> (`OK, content, [])
| Error (((See_other redirect | Found redirect | Moved_permanently redirect) as status), content) ->
let status = Status.to_httpcats status in
status, Content.Html content, [ "Location", redirect ]
| Error (status, content) ->
let status = Status.to_httpcats status in
let content = Content.Html content in
(status, content)
(status, content, [])
in
let session = Session.load request in
let session_headers =
@ -100,7 +103,7 @@ end = struct
in
let headers, content = prepare_content content in
let headers = H2.Headers.to_list headers in
let headers = session_headers @ headers in
let headers = session_headers @ headers @ status_headers in
let headers = H2.Headers.of_list headers in
Httpcats.Server.string ~headers ~status content
in

View File

@ -1,5 +1,7 @@
type error =
| Moved_permanently
| Moved_permanently of string
| Found of string
| See_other of string
| Bad_request
| Unauthorized
| Forbidden
@ -13,7 +15,9 @@ type error =
| Gateway_timeout
let to_httpcats = function
| Moved_permanently -> `Moved_permanently
| Moved_permanently _url -> `Moved_permanently
| Found _url -> `Found
| See_other _url -> `See_other
| Bad_request -> `Bad_request
| Unauthorized -> `Unauthorized
| Forbidden -> `Forbidden

View File

@ -1,5 +1,7 @@
type error =
| Moved_permanently
| Moved_permanently of string
| Found of string
| See_other of string
| Bad_request
| Unauthorized
| Forbidden