Changed handling of response headers to allow multiple values; added documentation...
[bpt/mlt.git] / src / lib / web.sig
CommitLineData
c0a3b488
AC
1(*
2 * Dynamic web page generation with Standard ML
3 * Copyright (C) 2003 Adam Chlipala
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *)
19
20(* CGI interaction *)
21
22signature WEB =
23sig
8291a2b9 24 val for : (int -> unit) -> int * int -> unit
870af305
AC
25 (* (for f (min, max)) runs f on i for every i from min to max, inclusive.
26 * min may also be greater than max, for backward order. *)
8291a2b9 27
c0a3b488 28 val print : string -> unit
870af305 29 (* Add to the web output buffer *)
b26ce3d9 30 val clear : unit -> unit
870af305 31 (* Clear web output buffer *)
b26ce3d9 32 val noOutput : unit -> bool
870af305 33 (* True if there is no output in the buffer *)
c0a3b488 34 val output : unit -> unit
870af305 35 (* Flush the buffer *)
c0a3b488 36
8291a2b9 37 val setParam : string * string list -> unit
870af305
AC
38 (* Set the values associated with a single URL parameter.
39 * Parameters acquire multiple values when things like the following
40 * appear in URL's: ...&x=1&x=2&...
41 *)
8291a2b9 42 val setSingleParam : string * string -> unit
870af305 43 (* Set a parameter with a single value *)
c0a3b488 44 val getParam : string -> string
870af305 45 (* Get the first value set for a parameter, or "" if none is set *)
8291a2b9 46 val getMultiParam : string -> string list
870af305 47 (* Get all values of a parameter *)
c0a3b488 48
8291a2b9 49 val pushParams : (string * string list) list -> unit
870af305 50 (* Save the current parameter map and set the new ones given *)
c0a3b488 51 val popParams : unit -> unit
870af305 52 (* Restore the last parameter map saved with pushParams *)
8291a2b9 53 val withParams : (unit -> 'a) -> (string * string list) list -> 'a
870af305
AC
54 (* (withParams f params) executes f with params added to the parameter
55 * map, removing them afterwards *)
8291a2b9
AC
56
57 val getCgi : string -> string option
870af305 58 (* Get a named value defined by the CGI protocol, such as HTTP_COOKIE *)
8291a2b9
AC
59
60 val html : string -> string
870af305 61 (* Escape a plaintext string to appear in HTML *)
8291a2b9 62 val htmlNl : string -> string
870af305 63 (* Like html, but changes newlines to <br>'s *)
16abb0f9 64 val urlEncode : string -> string
870af305 65 (* Escape a plaintext string to appear in a URL *)
8291a2b9
AC
66
67 exception Format of string
68 val stoi : string -> int
870af305 69 (* Convert a string to an int, raising Format on error *)
8291a2b9 70 val stor : string -> real
870af305 71 (* Convert a string to a real, raising Format on error *)
8291a2b9
AC
72
73 val summary : unit -> string
870af305 74 (* Debugging info on CGI state *)
b26ce3d9
AC
75
76 val getExn : unit -> exn
870af305 77 (* Get the current exception when in an exception handler template *)
b26ce3d9 78 val setExn : exn -> unit
870af305 79 (* Set the exception to be returned by getExn *)
16abb0f9 80
870af305
AC
81 val setHeader : string * string list -> unit
82 (* Set the values of an HTTP response header *)
83 val getHeader : string -> string list option
84 (* Get the values of an HTTP response header *)
85 val addHeader : string * string -> unit
86 (* Add a value for a header *)
87 val getSingleHeader : string -> string option
88 (* Get the first value of a header *)
16abb0f9
AC
89
90 type cookie = {name : string, value : string, expires : Date.date option,
91 domain : string option, path : string option, secure : bool}
870af305
AC
92 (* name: Key
93 * value: Data to associate with name
94 * expires: When browser should discard this cookie.
95 * NONE clears the cookie immediately. SOME of a date clears it at
96 * that date. Use a very far-off date for "non-expiring" cookies.
97 * domain: If NONE, cookie is valid in current domain.
98 * If SOME, specifies a particular domain pattern for the cookie.
99 * path: Like domain, but specifies path on a server
100 * secure: If set, cookie may only be transferred over HTTPS
101 *)
16abb0f9 102 val setCookie : cookie -> unit
870af305 103 (* Add a cookie set request to the HTTP response *)
16abb0f9 104 val getCookie : string -> string option
870af305 105 (* Get a cookie's value by looking up its name *)
16abb0f9
AC
106
107 val remoteHost : unit -> string option
870af305 108 (* Get REMOTE_HOST CGI variable *)
16abb0f9 109
870af305
AC
110 val plusSeconds : Time.time * int -> Time.time
111 (* Add seconds to a time *)
16abb0f9 112 val minusSeconds : Time.time * int -> Time.time
870af305 113 (* Subtract seconds from a time *)
16abb0f9
AC
114
115 val replaceUrlVar : string * string * string -> string
870af305
AC
116 (* (replaceUrlVar (url, name, value)) replaces the value of
117 * URL variable name in url by value. If name is not set in
118 * url, it is added.
119 *)
c0a3b488 120end