mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 11:15:35 -05:00
expose Response.make_void
it only has no body if the http code is compatible with it. close #62
This commit is contained in:
parent
9c2cf0900d
commit
997f7aa868
3 changed files with 8 additions and 2 deletions
|
|
@ -249,7 +249,7 @@ let add_vfs_ ~on_fs ~top ~config ~vfs:((module VFS:VFS) as vfs) ~prefix server :
|
|||
(* redirect using path, not full path *)
|
||||
let new_path = "/" // prefix // path // "index.html" in
|
||||
S._debug (fun k->k "redirect to `%s`" new_path);
|
||||
S.Response.make_raw ~code:301 ""
|
||||
S.Response.make_void ~code:301 ()
|
||||
~headers:S.Headers.(empty |> set "location" new_path)
|
||||
| Lists | Index_or_lists ->
|
||||
let body = html_list_dir ~prefix vfs path ~parent |> Html.to_string_top in
|
||||
|
|
|
|||
|
|
@ -354,7 +354,9 @@ module Response = struct
|
|||
{ code; headers; body=`Stream body; }
|
||||
|
||||
let make_void ?(headers=[]) ~code () : t =
|
||||
{ code; headers; body=`Void; }
|
||||
let is_ok = code < 200 || code = 204 || code = 304 in
|
||||
if is_ok then { code; headers; body=`Void; }
|
||||
else make_raw ~headers ~code "" (* invalid to not have a body *)
|
||||
|
||||
let make_string ?headers r = match r with
|
||||
| Ok body -> make_raw ?headers ~code:200 body
|
||||
|
|
|
|||
|
|
@ -232,6 +232,10 @@ module Response : sig
|
|||
(** Same as {!make_raw} but with a stream body. The body will be sent with
|
||||
the chunked transfer-encoding. *)
|
||||
|
||||
val make_void : ?headers:Headers.t -> code:int -> unit -> t
|
||||
(** Return a response without a body at all.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val make :
|
||||
?headers:Headers.t ->
|
||||
(body, Response_code.t * string) result -> t
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue