3 OCaml HTTP - do it yourself (fully OCaml) HTTP daemon
5 Copyright (C) <2002-2005> Stefano Zacchiroli <zack@cs.unibo.it>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation, version 2.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 (** Object Oriented representation of HTTP messages *)
26 (** OO representation of an HTTP message
27 @param entity body included in the message
28 @param headers message headers shipped with the message *)
29 class virtual message:
30 body: string -> headers: (string * string) list -> version: version option ->
31 clisockaddr: Unix.sockaddr -> srvsockaddr: Unix.sockaddr ->
34 (** @return message HTTP version, it can be None because older version
35 of the HTTP protocol don't require HTTP version to be told between
36 message source and destination *)
37 method version: version option
39 (** set message HTTP version *)
40 method setVersion: version -> unit
42 (** @return message body *)
45 (** set message body *)
46 method setBody: string -> unit
48 (** @return a Buffer.t connected to message body (Warning: changing this
49 buffer will change message body too) *)
50 method bodyBuf: Buffer.t
52 (** set a new Buffer.t used to keep message body *)
53 method setBodyBuf: Buffer.t -> unit
55 (** append a string to message body *)
56 method addBody: string -> unit
58 (** append a whole buffer to message body *)
59 method addBodyBuf: Buffer.t -> unit
61 (** {i header name comparison are performed in a case-insensitive manner
62 as required by RFC2616, actually the implementation works converting all
63 header names in lowercase} *)
65 (** add an HTTP header
66 @param name header's name
67 @param value header's value *)
68 method addHeader: name:string -> value:string -> unit
70 (** add a list of HTTP headers
71 @param headers a list of pairs: header_name, header_value *)
72 method addHeaders: (string * string) list -> unit
74 (** like addHeader but replace previous definition of the same header *)
75 method replaceHeader: name:string -> value:string -> unit
77 (** like addHeaders but replace previous definition of headers that were
79 method replaceHeaders: (string * string) list -> unit
81 (** remove _all_ occurences of an HTTP header from the message
82 @param name name of the header to be removed *)
83 method removeHeader: name:string -> unit
85 (** @return true if given header exists in message, false otherwise *)
86 method hasHeader: name:string -> bool
88 (** @return value associated to a given header
89 @param name name of the header to lookup
90 @raise Header_not_found if given header wasn't defined in message *)
91 method header: name:string -> string
93 (** @return the full set of headers defined for this message, the value
94 returned is an association list from headers name to headers value, an
95 header may occurs more that once in the list *)
96 method headers: (string * string) list
99 (** @return client Unix.sockaddr *)
100 method clientSockaddr: Unix.sockaddr
102 (** @return client address pretty printed *)
103 method clientAddr: string
105 (** @return client port *)
106 method clientPort: int
108 (** @return server Unix.sockaddr *)
109 method serverSockaddr: Unix.sockaddr
111 (** @return server address pretty printed *)
112 method serverAddr: string
114 (** @return server port *)
115 method serverPort: int
118 (** @return for requests first request line, for responses first
120 User by derived requests and responses to implement toString method *)
121 method private virtual fstLineToString: string
123 (** @return a string representation of the message *)
124 method toString: string
126 (** serialize the message over an output channel *)
127 method serialize: out_channel -> unit