Add cache-control headers to hopefully disable caching on streaming responses; untested so far
This commit is contained in:
parent
0f8efaf4cf
commit
66a6182a40
6
httpd.ml
6
httpd.ml
|
@ -56,6 +56,12 @@ let content_type_header_name = "Content-Type"
|
||||||
let html_content_type_header = (content_type_header_name, html_content_type)
|
let html_content_type_header = (content_type_header_name, html_content_type)
|
||||||
let text_content_type_header = (content_type_header_name, text_content_type)
|
let text_content_type_header = (content_type_header_name, text_content_type)
|
||||||
|
|
||||||
|
let disable_cache_headers () =
|
||||||
|
["Expires", "Thu, 01 Jan 1981 00:00:00 GMT";
|
||||||
|
"Last-Modified", Httpd_date.http_gmtime (Unix.time ());
|
||||||
|
"Cache-Control", "no-cache, must-revalidate, max-age=0";
|
||||||
|
"Pragma", "no-cache"]
|
||||||
|
|
||||||
let add_completion_callback resp cb =
|
let add_completion_callback resp cb =
|
||||||
{resp with completion_callbacks = cb :: resp.completion_callbacks}
|
{resp with completion_callbacks = cb :: resp.completion_callbacks}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
(* Copyright 2012 Tony Garnock-Jones <tonygarnockjones@gmail.com>. *)
|
||||||
|
|
||||||
|
(* This file is part of Ocamlmsg. *)
|
||||||
|
|
||||||
|
(* Ocamlmsg is free software: you can redistribute it and/or modify it *)
|
||||||
|
(* under the terms of the GNU General Public License as published by the *)
|
||||||
|
(* Free Software Foundation, either version 3 of the License, or (at your *)
|
||||||
|
(* option) any later version. *)
|
||||||
|
|
||||||
|
(* Ocamlmsg is distributed in the hope that it will be useful, but *)
|
||||||
|
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
|
||||||
|
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
|
||||||
|
(* General Public License for more details. *)
|
||||||
|
|
||||||
|
(* You should have received a copy of the GNU General Public License *)
|
||||||
|
(* along with Ocamlmsg. If not, see <http://www.gnu.org/licenses/>. *)
|
||||||
|
|
||||||
|
open Unix
|
||||||
|
|
||||||
|
let days = ["Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"]
|
||||||
|
let months = ["Jan"; "Feb"; "Mar"; "Apr"; "May"; "Jun"; "Jul"; "Aug"; "Sep"; "Oct"; "Nov"; "Dec"]
|
||||||
|
|
||||||
|
(* Example: *)
|
||||||
|
(* Wed, 15 Nov 1995 06:25:24 GMT *)
|
||||||
|
let http_gmtime t =
|
||||||
|
let tm = gmtime t in
|
||||||
|
Printf.sprintf "%s, %02d %s %04d %02d:%02d:%02d GMT"
|
||||||
|
(List.nth days tm.tm_wday) tm.tm_mday (List.nth months tm.tm_mon) (tm.tm_year + 1900)
|
||||||
|
tm.tm_hour tm.tm_min tm.tm_sec
|
|
@ -46,8 +46,10 @@ let rec api_tap_source id r =
|
||||||
Sexp.Str "", Sexp.Str ""));
|
Sexp.Str "", Sexp.Str ""));
|
||||||
Httpd.add_completion_callback
|
Httpd.add_completion_callback
|
||||||
(Httpd.resp_generic 200 "Streaming"
|
(Httpd.resp_generic 200 "Streaming"
|
||||||
[Httpd.text_content_type_header;
|
([Httpd.text_content_type_header;
|
||||||
"Access-Control-Allow-Origin", "*"]
|
"Access-Control-Allow-Origin", "*";
|
||||||
|
"Date", Httpd_date.http_gmtime (Unix.time ())]
|
||||||
|
@ Httpd.disable_cache_headers ())
|
||||||
(Httpd.Variable
|
(Httpd.Variable
|
||||||
(Stringstream.switch_after 131072
|
(Stringstream.switch_after 131072
|
||||||
(Stringstream.seq id_block_and_padding (Stringstream.make (message_stream ch)))
|
(Stringstream.seq id_block_and_padding (Stringstream.make (message_stream ch)))
|
||||||
|
|
Loading…
Reference in New Issue