@@ -7,8 +7,10 @@ class string;
77class ostream ;
88class socket_stream ;
99class http_header ;
10+ class http_client ;
1011class HttpCookie ;
1112class HttpServlet ;
13+ class HttpServletRequest ;
1214
1315/* *
1416 * 与 HTTP 客户端响应相关的类,该类不应被继承,用户也不需要
@@ -46,20 +48,30 @@ class ACL_CPP_API HttpServletResponse
4648 /* *
4749 * 设置与 HTTP 客户端保持联系长连接
4850 * @param on {bool}
51+ * @return {HttpServletResponse&}
4952 */
5053 HttpServletResponse& setKeepAlive (bool on);
5154
5255 /* *
5356 * 设置 HTTP 响应数据体的 Content-Type 字段值,可字段值可以为:
5457 * text/html 或 text/html; charset=utf8 格式
5558 * @param value {const char*} 字段值
59+ * @return {HttpServletResponse&}
5660 */
5761 HttpServletResponse& setContentType (const char * value);
5862
63+ /* *
64+ * 设置 HTTP 响应数据体采用 gzip 压缩格式
65+ * @param gzip {bool} 是否采用 gzip 压缩格式
66+ * @return {HttpServletResponse&}
67+ */
68+ HttpServletResponse& setContentEncoding (bool gzip);
69+
5970 /* *
6071 * 设置 HTTP 响应数据体中字符集,当已经在 setContentType 设置
6172 * 了字符集,则就不必再调用本函数设置字符集
6273 * @param charset {const char*} 响应体数据的字符集
74+ * @return {HttpServletResponse&}
6375 */
6476 HttpServletResponse& setCharacterEncoding (const char * charset);
6577
@@ -88,8 +100,8 @@ class ACL_CPP_API HttpServletResponse
88100 * 对于分区下载,调用本函数设置数据下载的偏移位置(下标从 0 开始)
89101 * @param from {http_off_t} 数据区间起始偏移位置(下标从 0 开始计算)
90102 * @param to {http_off_t} 数据区间结束位置(该值需小于总数据长度)
91- * @param total {http_off_t} 总数据长度,当数据源为一个静态文件时该值应
92- * 等于该文件的总长度大小
103+ * @param total {http_off_t} 总数据长度,当数据源为一个静态文件时该值
104+ * 应等于该文件的总长度大小
93105 * @return {HttpServletResponse&}
94106 */
95107#if defined(_WIN32) || defined(_WIN64)
@@ -178,17 +190,18 @@ class ACL_CPP_API HttpServletResponse
178190
179191 /* *
180192 * 带格式方式向 HTTP 客户端发送响应数据,内部自动调用
181- * HttpServletResponse::write(const void*, size_t) 过程,
182- * 在使用 chunked 方式传输数据时,应该应该最后再调用 write(NULL, 0) 表示数据结束
193+ * HttpServletResponse::write(const void*, size_t) 过程,在使用
194+ * chunked 方式传输数据时,应该应该最后再调用 write(NULL, 0)
195+ * 表示数据结束
183196 * @param fmt {const char*} 变参格式字符串
184197 * @return {int} 成功则返回值 > 0,否则返回 -1
185198 */
186199 int format (const char * fmt, ...) ACL_CPP_PRINTF(2 , 3 );
187200
188201 /* *
189202 * 带格式方式向 HTTP 客户端发送响应数据,内部自动调用
190- * HttpServletResponse::write(const string&) 过程,
191- * 在使用 chunked 方式传输数据时,应该应该最后再调用 write(NULL, 0) 表示数据结束
203+ * HttpServletResponse::write(const string&) 过程,在使用 chunked
204+ * 方式传输数据时,应该应该最后再调用 write(NULL, 0) 表示数据结束
192205 * @param fmt {const char*} 变参格式字符串
193206 * @param ap {va_list} 变参列表
194207 * @return {int} 成功则返回值 > 0,否则返回 -1
@@ -214,8 +227,16 @@ class ACL_CPP_API HttpServletResponse
214227 */
215228 ostream& getOutputStream (void ) const ;
216229
230+ /* *
231+ * 设置 http 请求对象,该函数目前只应被 HttpServlet 类内部调用
232+ * @param request {HttpServletRequest*}
233+ */
234+ void setHttpServletRequest (HttpServletRequest* request);
235+
217236private:
218237 socket_stream& stream_; // 客户端连接流
238+ HttpServletRequest* request_; // http 请求对象
239+ http_client* client_; // http 响应流对象
219240 http_header* header_; // http 响应头
220241 char charset_[32 ]; // 字符集
221242 char content_type_[32 ]; // content-type 类型
0 commit comments