21
21
#include "Plist.hpp"
24
#ifndef AFNIX_BUFFER_HPP
24
#ifndef AFNIX_BLOCKBUFFER_HPP
25
#include "BlockBuffer.hpp"
30
30
/// the HttpProto class is a base class that ease the deployement of the
31
31
/// http protocol. The base class is built with a property list which is
32
/// used to define the message header. The class alo defines the write
32
/// used to define the message header. The class also defines the write
33
33
/// methods which are used to write a message either on an output stream
34
34
/// or into a buffer.
35
35
/// @author amaury darsch
37
37
class HttpProto : public virtual Object {
39
/// map a http status code
39
/// the protocol object type
41
HTTP_SERVER, // protocol server side
42
HTTP_CLIENT // protocol client side
48
HEAD_ACHS, // Accept-Charset
49
HEAD_AENC, // Accept-Encoding
50
HEAD_ALNG, // Accept-Language
51
HEAD_ARNG, // Accept-Ranges
54
HEAD_AUTH, // Authorization
55
HEAD_CCTL, // Cache-Control
56
HEAD_CONN, // Connection
57
HEAD_CENC, // Content-Encoding
58
HEAD_CLNG, // Content-Language
59
HEAD_CLEN, // Content-Length
60
HEAD_CLOC, // Content-Location
61
HEAD_CMD5, // Content-MD5
62
HEAD_CRNG, // Content-Range
63
HEAD_CTYP, // Content-Type
70
HEAD_IFMT, // If-Match
71
HEAD_IFMS, // If-Modified-Since
72
HEAD_IFNM, // If-None-Match
73
HEAD_IFRG, // If-Range
74
HEAD_IFUS, // If-Unmodified-Since
75
HEAD_LMOD, // Last-Modified
76
HEAD_MLOC, // Location
77
HEAD_MFWD, // Max-Forwards
79
HEAD_PXTH, // Proxy-Authenticate
80
HEAD_PXAT, // Proxy-Authorization
83
HEAD_RAFT, // Retry-After
87
HEAD_TENC, // Transfer-Encoding
89
HEAD_UAGT, // User-Agent
93
HEAD_WWWA, // WWW-Authenticate
94
HEAD_COK0, // Set-Cookie
95
HEAD_COK1 // Set-Cookie2
98
/// @return the default http version
99
static String getxdef (void);
101
/// map a header field to a string
102
/// @param hflg the header field to map
103
static String hfldtos (const t_hfld hfld);
105
/// map a http status code to a string
40
106
/// @param code the code to map
41
static String mapcode (const long code);
107
static String codetos (const long code);
110
/// the protocol version
112
/// the protocol type
114
/// the http header list
48
/// set a header property
118
/// create a default http protocol
121
/// create a default http protocol by type
122
/// @param ptyp the protocol type
123
HttpProto (const t_ptyp ptyp);
125
/// copy construct this http protocol
126
/// @param that the object to copy
127
HttpProto (const HttpProto& that);
129
/// assign a http protocol to this one
130
/// @param that the object to assign
131
HttpProto& operator = (const HttpProto& that);
133
/// reset this protocol object
134
virtual void reset (void);
136
/// parse an input stream
137
/// @param is the input stream to parse
138
virtual void parse (InputStream& is) =0;
140
/// set the protocol version
141
/// @param vers the version to set
142
virtual void setvers (const String& vers);
144
/// @return the protocol version
145
virtual String getvers (void) const;
147
/// @return the header length
148
virtual long hlength (void) const;
150
/// @return true if a header property exists
151
virtual bool hexists (const String& name) const;
153
/// @return true if a header property exists by field
154
virtual bool hexists (const t_hfld hfld) const;
156
/// set a header property by name and litteral
49
157
/// @param name the property name
50
158
/// @param lval the property value
51
virtual void sethead (const String& name, const Literal& pval);
159
virtual void hset (const String& name, const Literal& pval);
161
/// set a header property by field and litteral
162
/// @param hfld the header field
163
/// @param lval the property value
164
virtual void hset (const t_hfld hfld, const Literal& pval);
166
/// @return a header property by index
167
virtual Property* hget (const long index) const;
169
/// @return a header property by name
170
virtual Property* hfind (const String& name) const;
172
/// @return a header property by field
173
virtual Property* hfind (const t_hfld hfld) const;
175
/// @return a header property by name or throw an exception
176
virtual Property* hlookup (const String& name) const;
178
/// @return a header property by field or throw an exception
179
virtual Property* hlookup (const t_hfld hfld) const;
181
/// @return a header property value by name
182
virtual String hmap (const String& name) const;
184
/// @return a header property value by field
185
virtual String hmap (const t_hfld hfld) const;
187
/// @return true if the media type is defined
188
virtual bool ismedia (void) const;
190
/// @return the response media type
191
virtual String getmedia (void) const;
193
/// @return true if the encoding mode is defined
194
virtual bool isemod (void) const;
196
/// @return the response encoding mode
197
virtual String getemod (void) const;
199
/// @return true if the content length is defined
200
virtual bool isclen (void) const;
202
/// @return the header content length
203
virtual long getclen (void) const;
205
/// get the content string
206
/// @param is the input stream to parse
207
virtual String getcstr (InputStream& is);
209
/// parse a header from an input stream
210
/// @param is the input stream to parse
211
virtual void hparse (InputStream& is);
53
213
/// write the http header to an output stream
54
214
/// @param os the output stream
55
virtual void write (Output& os) const;
215
virtual void write (OutputStream& os) const;
57
217
/// write the http header to a buffer
58
218
/// @param buf the target buffer