53
53
const char *getNameCString() { return iName ? iName->getCString() : ""; }
54
54
const char *getValueCString() { return iValue ? iValue->getCString() : ""; }
56
void write(CSOutputStream *out);
56
void write(CSOutputStream *out, bool trace);
58
58
friend class CSHTTPHeaders;
67
67
class CSHTTPHeaders {
69
CSHTTPHeaders(): iHeaders(NULL), iKeepAlive(false), iExpect100Continue(false), iUnknownEpectHeader(false) { }
69
CSHTTPHeaders(CSVector *list = NULL): iHeaders(list), iKeepAlive(false), iExpect100Continue(false), iUnknownEpectHeader(false) { }
70
70
virtual ~CSHTTPHeaders() { if (iHeaders) iHeaders->release();}
72
72
void clearHeaders();
78
78
void addHeader(const char *name, uint32_t nlen, const char *value, uint32_t vlen);
79
79
void addHeader(CSString *name, CSString *value);
80
80
void addHeader(const char *name, CSString *value);
81
void addHeader(const char *name, uint64_t value);
81
82
void removeHeader(const char *name);
82
83
void removeHeader(CSString *name);
83
84
CSString *getHeaderValue(const char *name);
84
void writeHeader(CSOutputStream *out);
85
const char *getHeaderCStringValue(const char *name);
86
void writeHeader(CSOutputStream *out, bool trace);
86
88
bool expect100Continue();
87
89
bool unknownEpectHeader();
106
108
bool iUnknownEpectHeader;
111
class CSRefHTTPHeaders : public CSHTTPHeaders, public CSRefObject {
113
CSRefHTTPHeaders(CSVector *list):CSHTTPHeaders(list){}
114
~CSRefHTTPHeaders(){}
109
117
class CSHTTPInputStream : public CSInputStream, public CSHTTPHeaders {
111
119
CSHTTPInputStream(CSInputStream *s);
112
120
virtual ~CSHTTPInputStream();
115
uint64_t getContentLength();
122
void readHead(bool trace = false);
124
bool getContentLength(uint64_t *length);
116
125
const char *getMethod();
126
char *getBodyData() { return iBody.getCString(); };
127
size_t getBodyLength() { return iBody.length(); };
128
void setBody(CSStringBufferImpl *buf) { iBody.take(buf); }
117
129
int getStatus() { return iStatus; }
118
130
CSString *getStatusPhrase() { return iStatusPhrase; }
119
131
CSString *getRequestURI() { return iRequestURI; }
153
168
void setContentLength(uint64_t size) { iContentLength = size; }
154
169
void setRange(uint64_t size, uint64_t offset, uint64_t total) { iRangeSize = size; iRangeOffset = offset; iTotalLength = total;}
156
void writeHead(); // Writes a standard HTTP header.
157
void writeHeaders(); // Write the current headers.
171
void writeHead(bool trace = false); // Writes a standard HTTP header.
172
void writeHeaders(bool trace = false); // Write the current headers.
159
174
void clearBody();
160
175
void writeBody();
177
// The virtual and non virtual print() methods
178
// must be kept seperate to avoid possible compiler
179
// warnings about hidden methods.
180
void print(const char *str, bool trace);
181
void print(int32_t value, bool trace);
182
void print(uint64_t value, bool trace);
184
virtual void print(const char *str) {print(str, false);}
185
virtual void print(CSString *s) {print(s->getCString(), false);}
186
virtual void print(int32_t value) {print(value, false);}
187
virtual void print(uint64_t value) {print(value, false);}
162
189
void appendBody(const char *str);
163
void appendBody(int value);
190
void appendBody(int32_t value);
191
void appendBody(uint32_t value);
192
void appendBody(uint64_t value);
193
const char *getBodyData();
194
size_t getBodyLength();
195
void setBody(CSStringBufferImpl *buf);
165
197
virtual void close();
173
205
virtual void write(char b);
175
virtual void reset() {iOutput->reset();}
207
virtual void reset() { iOutput->reset(); }
209
virtual const char *identify() { return iOutput->identify(); }
177
211
static const char *getReasonPhrase(int code);