| 1212 | } |
| 1213 | |
| 1214 | bool http_header::build_response(string& out) const |
| 1215 | { |
| 1216 | out.clear(); |
| 1217 | |
| 1218 | if (fixed_) { |
| 1219 | build_common(out); |
| 1220 | out << "\r\n"; |
| 1221 | return true; |
| 1222 | } |
| 1223 | |
| 1224 | if (status_ > 0) { |
| 1225 | if (cgi_mode_) { |
| 1226 | out.format("STATUS: %d\r\n", status_); |
| 1227 | } else { |
| 1228 | if (version_[0] != 0) { |
| 1229 | out << "HTTP/" << version_ << "\r\n"; |
| 1230 | } else { |
| 1231 | out = "HTTP/1.1 "; |
| 1232 | } |
| 1233 | out << status_ << " " << http_status(status_) << "\r\n"; |
| 1234 | |
| 1235 | time_t now = time(NULL); |
| 1236 | char buf[64]; |
| 1237 | date_format(buf, sizeof(buf), now); |
| 1238 | out << "Date: " << buf << "\r\n"; |
| 1239 | //out << "Server: acl\r\n"; |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | build_common(out); |
| 1244 | |
| 1245 | if (!cookies_.empty()) { |
| 1246 | std::list<HttpCookie*>::const_iterator it = cookies_.begin(); |
| 1247 | for (; it != cookies_.end(); ++it) { |
| 1248 | out.format_append("Set-Cookie: %s=%s", |
| 1249 | (*it)->getName(), (*it)->getValue()); |
| 1250 | const std::list<HTTP_PARAM*>& params = (*it)->getParams(); |
| 1251 | std::list<HTTP_PARAM*>::const_iterator cit = params.begin(); |
| 1252 | for (; cit != params.end(); ++ cit) { |
| 1253 | out.format_append("; %s=%s", |
| 1254 | (*cit)->name, (*cit)->value); |
| 1255 | } |
| 1256 | out << "\r\n"; |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | if (upgrade_ && *upgrade_) { |
| 1261 | if (ws_sec_key_ && *ws_sec_key_) { |
| 1262 | append_accept_key(ws_sec_key_, out); |
| 1263 | } |
| 1264 | |
| 1265 | out << "\r\n"; |
| 1266 | return true; |
| 1267 | } |
| 1268 | |
| 1269 | // ���ӷֶ���Ӧ�ֶ� |
| 1270 | if (range_from_ >= 0 |
| 1271 | && range_to_ >= range_from_ && range_total_ > 0) { |
no test coverage detected