Check if-not-modified
We are still reading the whole file from disk even when it's not needed.
This commit is contained in:
parent
1ce4c11c05
commit
847e0cffe4
1 changed files with 11 additions and 5 deletions
|
@ -183,6 +183,7 @@ let add_routes datadir =
|
||||||
let _job_name = Dream.param "job" req
|
let _job_name = Dream.param "job" req
|
||||||
and build = Dream.param "build" req
|
and build = Dream.param "build" req
|
||||||
and filepath = Dream.path req |> String.concat "/" in
|
and filepath = Dream.path req |> String.concat "/" in
|
||||||
|
let if_none_match = Dream.header "if-none-match" req in
|
||||||
(* XXX: We don't check safety of [file]. This should be fine however since
|
(* XXX: We don't check safety of [file]. This should be fine however since
|
||||||
* we don't use [file] for the filesystem but is instead used as a key for
|
* we don't use [file] for the filesystem but is instead used as a key for
|
||||||
* lookup in the data table of the 'full' file. *)
|
* lookup in the data table of the 'full' file. *)
|
||||||
|
@ -200,11 +201,16 @@ let add_routes datadir =
|
||||||
Log.warn (fun m -> m "Error getting build artifact: %a" pp_error e);
|
Log.warn (fun m -> m "Error getting build artifact: %a" pp_error e);
|
||||||
Dream.respond ~status:`Internal_Server_Error "Error getting build artifact"
|
Dream.respond ~status:`Internal_Server_Error "Error getting build artifact"
|
||||||
| Ok (data, digest) ->
|
| Ok (data, digest) ->
|
||||||
let headers = [
|
let etag = Base64.encode_string (Cstruct.to_string digest) in
|
||||||
"Content-Type", mime_lookup filepath;
|
match if_none_match with
|
||||||
"ETag",(Base64.encode_string (Cstruct.to_string digest));
|
| Some etag' when etag = etag' ->
|
||||||
] in
|
Dream.empty `Not_Modified
|
||||||
Dream.respond ~headers data
|
| _ ->
|
||||||
|
let headers = [
|
||||||
|
"Content-Type", mime_lookup filepath;
|
||||||
|
"ETag", etag;
|
||||||
|
] in
|
||||||
|
Dream.respond ~headers data
|
||||||
in
|
in
|
||||||
|
|
||||||
let upload req =
|
let upload req =
|
||||||
|
|
Loading…
Reference in a new issue