OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 // Helpers | 30 // Helpers |
31 ////////////////////////////////////////////////////////////////////// | 31 ////////////////////////////////////////////////////////////////////// |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 const size_t kCacheHeader = 0; | 35 const size_t kCacheHeader = 0; |
36 const size_t kCacheBody = 1; | 36 const size_t kCacheBody = 1; |
37 | 37 |
38 // Convert decimal string to integer | 38 // Convert decimal string to integer |
39 bool HttpStringToUInt(const std::string& str, size_t* val) { | 39 bool HttpStringToUInt(const std::string& str, size_t* val) { |
40 RTC_DCHECK(NULL != val); | 40 RTC_DCHECK(nullptr != val); |
41 char* eos = NULL; | 41 char* eos = nullptr; |
42 *val = strtoul(str.c_str(), &eos, 10); | 42 *val = strtoul(str.c_str(), &eos, 10); |
43 return (*eos == '\0'); | 43 return (*eos == '\0'); |
44 } | 44 } |
45 | 45 |
46 bool HttpShouldCache(const HttpTransaction& t) { | 46 bool HttpShouldCache(const HttpTransaction& t) { |
47 bool verb_allows_cache = (t.request.verb == HV_GET) | 47 bool verb_allows_cache = (t.request.verb == HV_GET) |
48 || (t.request.verb == HV_HEAD); | 48 || (t.request.verb == HV_HEAD); |
49 bool is_range_response = t.response.hasHeader(HH_CONTENT_RANGE, NULL); | 49 bool is_range_response = t.response.hasHeader(HH_CONTENT_RANGE, nullptr); |
50 bool has_expires = t.response.hasHeader(HH_EXPIRES, NULL); | 50 bool has_expires = t.response.hasHeader(HH_EXPIRES, nullptr); |
51 bool request_allows_cache = | 51 bool request_allows_cache = |
52 has_expires || (std::string::npos != t.request.path.find('?')); | 52 has_expires || (std::string::npos != t.request.path.find('?')); |
53 bool response_allows_cache = | 53 bool response_allows_cache = |
54 has_expires || HttpCodeIsCacheable(t.response.scode); | 54 has_expires || HttpCodeIsCacheable(t.response.scode); |
55 | 55 |
56 bool may_cache = verb_allows_cache | 56 bool may_cache = verb_allows_cache |
57 && request_allows_cache | 57 && request_allows_cache |
58 && response_allows_cache | 58 && response_allows_cache |
59 && !is_range_response; | 59 && !is_range_response; |
60 | 60 |
61 std::string value; | 61 std::string value; |
62 if (t.response.hasHeader(HH_CACHE_CONTROL, &value)) { | 62 if (t.response.hasHeader(HH_CACHE_CONTROL, &value)) { |
63 HttpAttributeList directives; | 63 HttpAttributeList directives; |
64 HttpParseAttributes(value.data(), value.size(), directives); | 64 HttpParseAttributes(value.data(), value.size(), directives); |
65 // Response Directives Summary: | 65 // Response Directives Summary: |
66 // public - always cacheable | 66 // public - always cacheable |
67 // private - do not cache in a shared cache | 67 // private - do not cache in a shared cache |
68 // no-cache - may cache, but must revalidate whether fresh or stale | 68 // no-cache - may cache, but must revalidate whether fresh or stale |
69 // no-store - sensitive information, do not cache or store in any way | 69 // no-store - sensitive information, do not cache or store in any way |
70 // max-age - supplants Expires for staleness | 70 // max-age - supplants Expires for staleness |
71 // s-maxage - use as max-age for shared caches, ignore otherwise | 71 // s-maxage - use as max-age for shared caches, ignore otherwise |
72 // must-revalidate - may cache, but must revalidate after stale | 72 // must-revalidate - may cache, but must revalidate after stale |
73 // proxy-revalidate - shared cache must revalidate | 73 // proxy-revalidate - shared cache must revalidate |
74 if (HttpHasAttribute(directives, "no-store", NULL)) { | 74 if (HttpHasAttribute(directives, "no-store", nullptr)) { |
75 may_cache = false; | 75 may_cache = false; |
76 } else if (HttpHasAttribute(directives, "public", NULL)) { | 76 } else if (HttpHasAttribute(directives, "public", nullptr)) { |
77 may_cache = true; | 77 may_cache = true; |
78 } | 78 } |
79 } | 79 } |
80 return may_cache; | 80 return may_cache; |
81 } | 81 } |
82 | 82 |
83 enum HttpCacheState { | 83 enum HttpCacheState { |
84 HCS_FRESH, // In cache, may use | 84 HCS_FRESH, // In cache, may use |
85 HCS_STALE, // In cache, must revalidate | 85 HCS_STALE, // In cache, must revalidate |
86 HCS_NONE // Not in cache | 86 HCS_NONE // Not in cache |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 enum HttpValidatorStrength { | 148 enum HttpValidatorStrength { |
149 HVS_NONE, | 149 HVS_NONE, |
150 HVS_WEAK, | 150 HVS_WEAK, |
151 HVS_STRONG | 151 HVS_STRONG |
152 }; | 152 }; |
153 | 153 |
154 HttpValidatorStrength | 154 HttpValidatorStrength |
155 HttpRequestValidatorLevel(const HttpRequestData& request) { | 155 HttpRequestValidatorLevel(const HttpRequestData& request) { |
156 if (HV_GET != request.verb) | 156 if (HV_GET != request.verb) |
157 return HVS_STRONG; | 157 return HVS_STRONG; |
158 return request.hasHeader(HH_RANGE, NULL) ? HVS_STRONG : HVS_WEAK; | 158 return request.hasHeader(HH_RANGE, nullptr) ? HVS_STRONG : HVS_WEAK; |
159 } | 159 } |
160 | 160 |
161 HttpValidatorStrength | 161 HttpValidatorStrength |
162 HttpResponseValidatorLevel(const HttpResponseData& response) { | 162 HttpResponseValidatorLevel(const HttpResponseData& response) { |
163 std::string value; | 163 std::string value; |
164 if (response.hasHeader(HH_ETAG, &value)) { | 164 if (response.hasHeader(HH_ETAG, &value)) { |
165 bool is_weak = (strnicmp(value.c_str(), "W/", 2) == 0); | 165 bool is_weak = (strnicmp(value.c_str(), "W/", 2) == 0); |
166 return is_weak ? HVS_WEAK : HVS_STRONG; | 166 return is_weak ? HVS_WEAK : HVS_STRONG; |
167 } | 167 } |
168 if (response.hasHeader(HH_LAST_MODIFIED, &value)) { | 168 if (response.hasHeader(HH_LAST_MODIFIED, &value)) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 HttpHeader header; | 202 HttpHeader header; |
203 if (FromString(header, it->first) && !HttpHeaderIsEndToEnd(header)) | 203 if (FromString(header, it->first) && !HttpHeaderIsEndToEnd(header)) |
204 continue; | 204 continue; |
205 length += it->first.length() + 2 + it->second.length() + 2; | 205 length += it->first.length() + 2 + it->second.length() + 2; |
206 if (!output) | 206 if (!output) |
207 continue; | 207 continue; |
208 std::string formatted_header(it->first); | 208 std::string formatted_header(it->first); |
209 formatted_header.append(": "); | 209 formatted_header.append(": "); |
210 formatted_header.append(it->second); | 210 formatted_header.append(it->second); |
211 formatted_header.append("\r\n"); | 211 formatted_header.append("\r\n"); |
212 StreamResult result = output->WriteAll(formatted_header.data(), | 212 StreamResult result = output->WriteAll( |
213 formatted_header.length(), | 213 formatted_header.data(), formatted_header.length(), nullptr, nullptr); |
214 NULL, NULL); | |
215 if (SR_SUCCESS != result) { | 214 if (SR_SUCCESS != result) { |
216 return false; | 215 return false; |
217 } | 216 } |
218 } | 217 } |
219 if (output && (SR_SUCCESS != output->WriteAll("\r\n", 2, NULL, NULL))) { | 218 if (output && (SR_SUCCESS != output->WriteAll("\r\n", 2, nullptr, nullptr))) { |
220 return false; | 219 return false; |
221 } | 220 } |
222 length += 2; | 221 length += 2; |
223 if (size) | 222 if (size) |
224 *size = length; | 223 *size = length; |
225 return true; | 224 return true; |
226 } | 225 } |
227 | 226 |
228 bool HttpReadCacheHeaders(StreamInterface* input, HttpResponseData* response, | 227 bool HttpReadCacheHeaders(StreamInterface* input, HttpResponseData* response, |
229 HttpData::HeaderCombine combine) { | 228 HttpData::HeaderCombine combine) { |
(...skipping 28 matching lines...) Expand all Loading... |
258 return true; | 257 return true; |
259 } | 258 } |
260 | 259 |
261 ////////////////////////////////////////////////////////////////////// | 260 ////////////////////////////////////////////////////////////////////// |
262 // HttpClient | 261 // HttpClient |
263 ////////////////////////////////////////////////////////////////////// | 262 ////////////////////////////////////////////////////////////////////// |
264 | 263 |
265 const size_t kDefaultRetries = 1; | 264 const size_t kDefaultRetries = 1; |
266 const size_t kMaxRedirects = 5; | 265 const size_t kMaxRedirects = 5; |
267 | 266 |
268 HttpClient::HttpClient(const std::string& agent, StreamPool* pool, | 267 HttpClient::HttpClient(const std::string& agent, |
| 268 StreamPool* pool, |
269 HttpTransaction* transaction) | 269 HttpTransaction* transaction) |
270 : agent_(agent), pool_(pool), | 270 : agent_(agent), |
271 transaction_(transaction), free_transaction_(false), | 271 pool_(pool), |
272 retries_(kDefaultRetries), attempt_(0), redirects_(0), | 272 transaction_(transaction), |
| 273 free_transaction_(false), |
| 274 retries_(kDefaultRetries), |
| 275 attempt_(0), |
| 276 redirects_(0), |
273 redirect_action_(REDIRECT_DEFAULT), | 277 redirect_action_(REDIRECT_DEFAULT), |
274 uri_form_(URI_DEFAULT), cache_(NULL), cache_state_(CS_READY), | 278 uri_form_(URI_DEFAULT), |
275 resolver_(NULL) { | 279 cache_(nullptr), |
| 280 cache_state_(CS_READY), |
| 281 resolver_(nullptr) { |
276 base_.notify(this); | 282 base_.notify(this); |
277 if (NULL == transaction_) { | 283 if (nullptr == transaction_) { |
278 free_transaction_ = true; | 284 free_transaction_ = true; |
279 transaction_ = new HttpTransaction; | 285 transaction_ = new HttpTransaction; |
280 } | 286 } |
281 } | 287 } |
282 | 288 |
283 HttpClient::~HttpClient() { | 289 HttpClient::~HttpClient() { |
284 base_.notify(NULL); | 290 base_.notify(nullptr); |
285 base_.abort(HE_SHUTDOWN); | 291 base_.abort(HE_SHUTDOWN); |
286 if (resolver_) { | 292 if (resolver_) { |
287 resolver_->Destroy(false); | 293 resolver_->Destroy(false); |
288 } | 294 } |
289 release(); | 295 release(); |
290 if (free_transaction_) | 296 if (free_transaction_) |
291 delete transaction_; | 297 delete transaction_; |
292 } | 298 } |
293 | 299 |
294 void HttpClient::reset() { | 300 void HttpClient::reset() { |
295 server_.Clear(); | 301 server_.Clear(); |
296 request().clear(true); | 302 request().clear(true); |
297 response().clear(true); | 303 response().clear(true); |
298 context_.reset(); | 304 context_.reset(); |
299 redirects_ = 0; | 305 redirects_ = 0; |
300 base_.abort(HE_OPERATION_CANCELLED); | 306 base_.abort(HE_OPERATION_CANCELLED); |
301 } | 307 } |
302 | 308 |
303 void HttpClient::OnResolveResult(AsyncResolverInterface* resolver) { | 309 void HttpClient::OnResolveResult(AsyncResolverInterface* resolver) { |
304 if (resolver != resolver_) { | 310 if (resolver != resolver_) { |
305 return; | 311 return; |
306 } | 312 } |
307 int error = resolver_->GetError(); | 313 int error = resolver_->GetError(); |
308 server_ = resolver_->address(); | 314 server_ = resolver_->address(); |
309 resolver_->Destroy(false); | 315 resolver_->Destroy(false); |
310 resolver_ = NULL; | 316 resolver_ = nullptr; |
311 if (error != 0) { | 317 if (error != 0) { |
312 LOG(LS_ERROR) << "Error " << error << " resolving name: " | 318 LOG(LS_ERROR) << "Error " << error << " resolving name: " |
313 << server_; | 319 << server_; |
314 onHttpComplete(HM_CONNECT, HE_CONNECT_FAILED); | 320 onHttpComplete(HM_CONNECT, HE_CONNECT_FAILED); |
315 } else { | 321 } else { |
316 connect(); | 322 connect(); |
317 } | 323 } |
318 } | 324 } |
319 | 325 |
320 void HttpClient::StartDNSLookup() { | 326 void HttpClient::StartDNSLookup() { |
(...skipping 15 matching lines...) Expand all Loading... |
336 | 342 |
337 void HttpClient::start() { | 343 void HttpClient::start() { |
338 if (base_.mode() != HM_NONE) { | 344 if (base_.mode() != HM_NONE) { |
339 // call reset() to abort an in-progress request | 345 // call reset() to abort an in-progress request |
340 RTC_NOTREACHED(); | 346 RTC_NOTREACHED(); |
341 return; | 347 return; |
342 } | 348 } |
343 | 349 |
344 RTC_DCHECK(!IsCacheActive()); | 350 RTC_DCHECK(!IsCacheActive()); |
345 | 351 |
346 if (request().hasHeader(HH_TRANSFER_ENCODING, NULL)) { | 352 if (request().hasHeader(HH_TRANSFER_ENCODING, nullptr)) { |
347 // Exact size must be known on the client. Instead of using chunked | 353 // Exact size must be known on the client. Instead of using chunked |
348 // encoding, wrap data with auto-caching file or memory stream. | 354 // encoding, wrap data with auto-caching file or memory stream. |
349 RTC_NOTREACHED(); | 355 RTC_NOTREACHED(); |
350 return; | 356 return; |
351 } | 357 } |
352 | 358 |
353 attempt_ = 0; | 359 attempt_ = 0; |
354 | 360 |
355 // If no content has been specified, using length of 0. | 361 // If no content has been specified, using length of 0. |
356 request().setHeader(HH_CONTENT_LENGTH, "0", false); | 362 request().setHeader(HH_CONTENT_LENGTH, "0", false); |
(...skipping 24 matching lines...) Expand all Loading... |
381 // Convert to relative uri form | 387 // Convert to relative uri form |
382 std::string host, path; | 388 std::string host, path; |
383 if (request().getRelativeUri(&host, &path)) { | 389 if (request().getRelativeUri(&host, &path)) { |
384 request().setHeader(HH_HOST, host); | 390 request().setHeader(HH_HOST, host); |
385 request().path = path; | 391 request().path = path; |
386 } else { | 392 } else { |
387 LOG(LS_WARNING) << "Couldn't obtain relative uri"; | 393 LOG(LS_WARNING) << "Couldn't obtain relative uri"; |
388 } | 394 } |
389 } | 395 } |
390 | 396 |
391 if ((NULL != cache_) && CheckCache()) { | 397 if ((nullptr != cache_) && CheckCache()) { |
392 return; | 398 return; |
393 } | 399 } |
394 | 400 |
395 connect(); | 401 connect(); |
396 } | 402 } |
397 | 403 |
398 void HttpClient::connect() { | 404 void HttpClient::connect() { |
399 int stream_err; | 405 int stream_err; |
400 if (server_.IsUnresolvedIP()) { | 406 if (server_.IsUnresolvedIP()) { |
401 StartDNSLookup(); | 407 StartDNSLookup(); |
402 return; | 408 return; |
403 } | 409 } |
404 StreamInterface* stream = pool_->RequestConnectedStream(server_, &stream_err); | 410 StreamInterface* stream = pool_->RequestConnectedStream(server_, &stream_err); |
405 if (stream == NULL) { | 411 if (stream == nullptr) { |
406 RTC_DCHECK(0 != stream_err); | 412 RTC_DCHECK(0 != stream_err); |
407 LOG(LS_ERROR) << "RequestConnectedStream error: " << stream_err; | 413 LOG(LS_ERROR) << "RequestConnectedStream error: " << stream_err; |
408 onHttpComplete(HM_CONNECT, HE_CONNECT_FAILED); | 414 onHttpComplete(HM_CONNECT, HE_CONNECT_FAILED); |
409 } else { | 415 } else { |
410 base_.attach(stream); | 416 base_.attach(stream); |
411 if (stream->GetState() == SS_OPEN) { | 417 if (stream->GetState() == SS_OPEN) { |
412 base_.send(&transaction_->request); | 418 base_.send(&transaction_->request); |
413 } | 419 } |
414 } | 420 } |
415 } | 421 } |
(...skipping 30 matching lines...) Expand all Loading... |
446 || !response().hasHeader(HH_LOCATION, location) | 452 || !response().hasHeader(HH_LOCATION, location) |
447 || (redirects_ >= kMaxRedirects)) | 453 || (redirects_ >= kMaxRedirects)) |
448 return false; | 454 return false; |
449 return (REDIRECT_ALWAYS == redirect_action_) | 455 return (REDIRECT_ALWAYS == redirect_action_) |
450 || (HC_SEE_OTHER == response().scode) | 456 || (HC_SEE_OTHER == response().scode) |
451 || (HV_HEAD == request().verb) | 457 || (HV_HEAD == request().verb) |
452 || (HV_GET == request().verb); | 458 || (HV_GET == request().verb); |
453 } | 459 } |
454 | 460 |
455 bool HttpClient::BeginCacheFile() { | 461 bool HttpClient::BeginCacheFile() { |
456 RTC_DCHECK(NULL != cache_); | 462 RTC_DCHECK(nullptr != cache_); |
457 RTC_DCHECK(CS_READY == cache_state_); | 463 RTC_DCHECK(CS_READY == cache_state_); |
458 | 464 |
459 std::string id = GetCacheID(request()); | 465 std::string id = GetCacheID(request()); |
460 CacheLock lock(cache_, id, true); | 466 CacheLock lock(cache_, id, true); |
461 if (!lock.IsLocked()) { | 467 if (!lock.IsLocked()) { |
462 LOG_F(LS_WARNING) << "Couldn't lock cache"; | 468 LOG_F(LS_WARNING) << "Couldn't lock cache"; |
463 return false; | 469 return false; |
464 } | 470 } |
465 | 471 |
466 if (HE_NONE != WriteCacheHeaders(id)) { | 472 if (HE_NONE != WriteCacheHeaders(id)) { |
(...skipping 20 matching lines...) Expand all Loading... |
487 } | 493 } |
488 | 494 |
489 HttpError HttpClient::WriteCacheHeaders(const std::string& id) { | 495 HttpError HttpClient::WriteCacheHeaders(const std::string& id) { |
490 std::unique_ptr<StreamInterface> stream( | 496 std::unique_ptr<StreamInterface> stream( |
491 cache_->WriteResource(id, kCacheHeader)); | 497 cache_->WriteResource(id, kCacheHeader)); |
492 if (!stream) { | 498 if (!stream) { |
493 LOG_F(LS_ERROR) << "Couldn't open header cache"; | 499 LOG_F(LS_ERROR) << "Couldn't open header cache"; |
494 return HE_CACHE; | 500 return HE_CACHE; |
495 } | 501 } |
496 | 502 |
497 if (!HttpWriteCacheHeaders(&transaction_->response, stream.get(), NULL)) { | 503 if (!HttpWriteCacheHeaders(&transaction_->response, stream.get(), nullptr)) { |
498 LOG_F(LS_ERROR) << "Couldn't write header cache"; | 504 LOG_F(LS_ERROR) << "Couldn't write header cache"; |
499 return HE_CACHE; | 505 return HE_CACHE; |
500 } | 506 } |
501 | 507 |
502 return HE_NONE; | 508 return HE_NONE; |
503 } | 509 } |
504 | 510 |
505 void HttpClient::CompleteCacheFile() { | 511 void HttpClient::CompleteCacheFile() { |
506 // Restore previous response document | 512 // Restore previous response document |
507 StreamTap* tap = static_cast<StreamTap*>(response().document.release()); | 513 StreamTap* tap = static_cast<StreamTap*>(response().document.release()); |
508 response().document.reset(tap->Detach()); | 514 response().document.reset(tap->Detach()); |
509 | 515 |
510 int error; | 516 int error; |
511 StreamResult result = tap->GetTapResult(&error); | 517 StreamResult result = tap->GetTapResult(&error); |
512 | 518 |
513 // Delete the tap and cache stream (which completes cache unlock) | 519 // Delete the tap and cache stream (which completes cache unlock) |
514 delete tap; | 520 delete tap; |
515 | 521 |
516 if (SR_SUCCESS != result) { | 522 if (SR_SUCCESS != result) { |
517 LOG(LS_ERROR) << "Cache file error: " << error; | 523 LOG(LS_ERROR) << "Cache file error: " << error; |
518 cache_->DeleteResource(GetCacheID(request())); | 524 cache_->DeleteResource(GetCacheID(request())); |
519 } | 525 } |
520 } | 526 } |
521 | 527 |
522 bool HttpClient::CheckCache() { | 528 bool HttpClient::CheckCache() { |
523 RTC_DCHECK(NULL != cache_); | 529 RTC_DCHECK(nullptr != cache_); |
524 RTC_DCHECK(CS_READY == cache_state_); | 530 RTC_DCHECK(CS_READY == cache_state_); |
525 | 531 |
526 std::string id = GetCacheID(request()); | 532 std::string id = GetCacheID(request()); |
527 if (!cache_->HasResource(id)) { | 533 if (!cache_->HasResource(id)) { |
528 // No cache file available | 534 // No cache file available |
529 return false; | 535 return false; |
530 } | 536 } |
531 | 537 |
532 HttpError error = ReadCacheHeaders(id, true); | 538 HttpError error = ReadCacheHeaders(id, true); |
533 | 539 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 cache_state_ = CS_READY; | 690 cache_state_ = CS_READY; |
685 cache_->DeleteResource(GetCacheID(request())); | 691 cache_->DeleteResource(GetCacheID(request())); |
686 // Continue processing response as normal | 692 // Continue processing response as normal |
687 } | 693 } |
688 | 694 |
689 RTC_DCHECK(!IsCacheActive()); | 695 RTC_DCHECK(!IsCacheActive()); |
690 if ((request().verb == HV_HEAD) || !HttpCodeHasBody(response().scode)) { | 696 if ((request().verb == HV_HEAD) || !HttpCodeHasBody(response().scode)) { |
691 // HEAD requests and certain response codes contain no body | 697 // HEAD requests and certain response codes contain no body |
692 data_size = 0; | 698 data_size = 0; |
693 } | 699 } |
694 if (ShouldRedirect(NULL) | 700 if (ShouldRedirect(nullptr) || |
695 || ((HC_PROXY_AUTHENTICATION_REQUIRED == response().scode) | 701 ((HC_PROXY_AUTHENTICATION_REQUIRED == response().scode) && |
696 && (PROXY_HTTPS == proxy_.type))) { | 702 (PROXY_HTTPS == proxy_.type))) { |
697 // We're going to issue another request, so ignore the incoming data. | 703 // We're going to issue another request, so ignore the incoming data. |
698 base_.set_ignore_data(true); | 704 base_.set_ignore_data(true); |
699 } | 705 } |
700 | 706 |
701 HttpError error = OnHeaderAvailable(base_.ignore_data(), chunked, data_size); | 707 HttpError error = OnHeaderAvailable(base_.ignore_data(), chunked, data_size); |
702 if (HE_NONE != error) { | 708 if (HE_NONE != error) { |
703 return error; | 709 return error; |
704 } | 710 } |
705 | 711 |
706 if ((NULL != cache_) | 712 if ((nullptr != cache_) && !base_.ignore_data() && |
707 && !base_.ignore_data() | 713 HttpShouldCache(*transaction_)) { |
708 && HttpShouldCache(*transaction_)) { | |
709 if (BeginCacheFile()) { | 714 if (BeginCacheFile()) { |
710 cache_state_ = CS_WRITING; | 715 cache_state_ = CS_WRITING; |
711 } | 716 } |
712 } | 717 } |
713 return HE_NONE; | 718 return HE_NONE; |
714 } | 719 } |
715 | 720 |
716 void HttpClient::onHttpComplete(HttpMode mode, HttpError err) { | 721 void HttpClient::onHttpComplete(HttpMode mode, HttpError err) { |
717 if (((HE_DISCONNECTED == err) || (HE_CONNECT_FAILED == err) | 722 if (((HE_DISCONNECTED == err) || (HE_CONNECT_FAILED == err) |
718 || (HE_SOCKET_ERROR == err)) | 723 || (HE_SOCKET_ERROR == err)) |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 } | 825 } |
821 | 826 |
822 ////////////////////////////////////////////////////////////////////// | 827 ////////////////////////////////////////////////////////////////////// |
823 // HttpClientDefault | 828 // HttpClientDefault |
824 ////////////////////////////////////////////////////////////////////// | 829 ////////////////////////////////////////////////////////////////////// |
825 | 830 |
826 HttpClientDefault::HttpClientDefault(SocketFactory* factory, | 831 HttpClientDefault::HttpClientDefault(SocketFactory* factory, |
827 const std::string& agent, | 832 const std::string& agent, |
828 HttpTransaction* transaction) | 833 HttpTransaction* transaction) |
829 : ReuseSocketPool(factory ? factory : Thread::Current()->socketserver()), | 834 : ReuseSocketPool(factory ? factory : Thread::Current()->socketserver()), |
830 HttpClient(agent, NULL, transaction) { | 835 HttpClient(agent, nullptr, transaction) { |
831 set_pool(this); | 836 set_pool(this); |
832 } | 837 } |
833 | 838 |
834 ////////////////////////////////////////////////////////////////////// | 839 ////////////////////////////////////////////////////////////////////// |
835 | 840 |
836 } // namespace rtc | 841 } // namespace rtc |
OLD | NEW |