OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #include "base/values.h" | 25 #include "base/values.h" |
26 #include "build/build_config.h" | 26 #include "build/build_config.h" |
27 #include "net/base/auth.h" | 27 #include "net/base/auth.h" |
28 #include "net/base/host_port_pair.h" | 28 #include "net/base/host_port_pair.h" |
29 #include "net/base/io_buffer.h" | 29 #include "net/base/io_buffer.h" |
30 #include "net/base/load_flags.h" | 30 #include "net/base/load_flags.h" |
31 #include "net/base/load_timing_info.h" | 31 #include "net/base/load_timing_info.h" |
32 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
33 #include "net/base/upload_data_stream.h" | 33 #include "net/base/upload_data_stream.h" |
34 #include "net/base/url_util.h" | 34 #include "net/base/url_util.h" |
35 #include "net/filter/filter_source_stream.h" | |
35 #include "net/http/http_auth.h" | 36 #include "net/http/http_auth.h" |
36 #include "net/http/http_auth_handler.h" | 37 #include "net/http/http_auth_handler.h" |
37 #include "net/http/http_auth_handler_factory.h" | 38 #include "net/http/http_auth_handler_factory.h" |
38 #include "net/http/http_basic_stream.h" | 39 #include "net/http/http_basic_stream.h" |
39 #include "net/http/http_chunked_decoder.h" | 40 #include "net/http/http_chunked_decoder.h" |
40 #include "net/http/http_network_session.h" | 41 #include "net/http/http_network_session.h" |
41 #include "net/http/http_proxy_client_socket.h" | 42 #include "net/http/http_proxy_client_socket.h" |
42 #include "net/http/http_proxy_client_socket_pool.h" | 43 #include "net/http/http_proxy_client_socket_pool.h" |
43 #include "net/http/http_request_headers.h" | 44 #include "net/http/http_request_headers.h" |
44 #include "net/http/http_request_info.h" | 45 #include "net/http/http_request_info.h" |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 const HttpResponseInfo& proxy_response, | 539 const HttpResponseInfo& proxy_response, |
539 const SSLConfig& used_ssl_config, | 540 const SSLConfig& used_ssl_config, |
540 const ProxyInfo& used_proxy_info, | 541 const ProxyInfo& used_proxy_info, |
541 HttpAuthController* auth_controller) { | 542 HttpAuthController* auth_controller) { |
542 DCHECK(stream_request_.get()); | 543 DCHECK(stream_request_.get()); |
543 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); | 544 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); |
544 | 545 |
545 establishing_tunnel_ = true; | 546 establishing_tunnel_ = true; |
546 response_.headers = proxy_response.headers; | 547 response_.headers = proxy_response.headers; |
547 response_.auth_challenge = proxy_response.auth_challenge; | 548 response_.auth_challenge = proxy_response.auth_challenge; |
549 | |
550 if (response_.headers.get() && !ContentEncodingsValid()) { | |
551 FilterSourceStream::ReportContentDecodingFailed(SourceStream::TYPE_UNKNOWN); | |
552 DoCallback(ERR_CONTENT_DECODING_FAILED); | |
553 return; | |
554 } | |
555 | |
548 headers_valid_ = true; | 556 headers_valid_ = true; |
549 server_ssl_config_ = used_ssl_config; | 557 server_ssl_config_ = used_ssl_config; |
550 proxy_info_ = used_proxy_info; | 558 proxy_info_ = used_proxy_info; |
551 | 559 |
552 auth_controllers_[HttpAuth::AUTH_PROXY] = auth_controller; | 560 auth_controllers_[HttpAuth::AUTH_PROXY] = auth_controller; |
553 pending_auth_target_ = HttpAuth::AUTH_PROXY; | 561 pending_auth_target_ = HttpAuth::AUTH_PROXY; |
554 | 562 |
555 DoCallback(OK); | 563 DoCallback(OK); |
556 } | 564 } |
557 | 565 |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1239 // bizarre for SPDY. Assuming this logic is useful at all. | 1247 // bizarre for SPDY. Assuming this logic is useful at all. |
1240 // TODO(davidben): Bubble the error code up so we do not cache? | 1248 // TODO(davidben): Bubble the error code up so we do not cache? |
1241 if (result == ERR_CONNECTION_CLOSED && response_.headers.get()) | 1249 if (result == ERR_CONNECTION_CLOSED && response_.headers.get()) |
1242 result = OK; | 1250 result = OK; |
1243 | 1251 |
1244 if (result < 0) | 1252 if (result < 0) |
1245 return HandleIOError(result); | 1253 return HandleIOError(result); |
1246 | 1254 |
1247 DCHECK(response_.headers.get()); | 1255 DCHECK(response_.headers.get()); |
1248 | 1256 |
1257 if (response_.headers.get() && !ContentEncodingsValid()) { | |
1258 FilterSourceStream::ReportContentDecodingFailed(SourceStream::TYPE_UNKNOWN); | |
1259 return ERR_CONTENT_DECODING_FAILED; | |
1260 } | |
1261 | |
1249 // On a 408 response from the server ("Request Timeout") on a stale socket, | 1262 // On a 408 response from the server ("Request Timeout") on a stale socket, |
1250 // retry the request. | 1263 // retry the request. |
1251 // Headers can be NULL because of http://crbug.com/384554. | 1264 // Headers can be NULL because of http://crbug.com/384554. |
1252 if (response_.headers.get() && response_.headers->response_code() == 408 && | 1265 if (response_.headers.get() && response_.headers->response_code() == 408 && |
1253 stream_->IsConnectionReused()) { | 1266 stream_->IsConnectionReused()) { |
1254 net_log_.AddEventWithNetErrorCode( | 1267 net_log_.AddEventWithNetErrorCode( |
1255 NetLogEventType::HTTP_TRANSACTION_RESTART_AFTER_ERROR, | 1268 NetLogEventType::HTTP_TRANSACTION_RESTART_AFTER_ERROR, |
1256 response_.headers->response_code()); | 1269 response_.headers->response_code()); |
1257 // This will close the socket - it would be weird to try and reuse it, even | 1270 // This will close the socket - it would be weird to try and reuse it, even |
1258 // if the server doesn't actually close it. | 1271 // if the server doesn't actually close it. |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1704 void HttpNetworkTransaction::CopyConnectionAttemptsFromStreamRequest() { | 1717 void HttpNetworkTransaction::CopyConnectionAttemptsFromStreamRequest() { |
1705 DCHECK(stream_request_); | 1718 DCHECK(stream_request_); |
1706 | 1719 |
1707 // Since the transaction can restart with auth credentials, it may create a | 1720 // Since the transaction can restart with auth credentials, it may create a |
1708 // stream more than once. Accumulate all of the connection attempts across | 1721 // stream more than once. Accumulate all of the connection attempts across |
1709 // those streams by appending them to the vector: | 1722 // those streams by appending them to the vector: |
1710 for (const auto& attempt : stream_request_->connection_attempts()) | 1723 for (const auto& attempt : stream_request_->connection_attempts()) |
1711 connection_attempts_.push_back(attempt); | 1724 connection_attempts_.push_back(attempt); |
1712 } | 1725 } |
1713 | 1726 |
1727 bool HttpNetworkTransaction::ContentEncodingsValid() const { | |
1728 HttpResponseHeaders* headers = GetResponseHeaders(); | |
1729 DCHECK(headers); | |
1730 | |
1731 std::string accept_encoding; | |
1732 request_headers_.GetHeader(HttpRequestHeaders::kAcceptEncoding, | |
1733 &accept_encoding); | |
1734 std::set<std::string> allowed_encodings; | |
1735 if (!HttpUtil::ParseAcceptEncoding(accept_encoding, &allowed_encodings)) | |
Randy Smith (Not in Mondays)
2017/03/21 21:23:20
Does this code handle the case where neither heade
eustas
2017/03/27 10:27:11
Added augmentation in parser: "" -> {"*"}.
Now ast
| |
1736 return false; | |
1737 | |
1738 std::string content_encoding; | |
1739 headers->GetNormalizedHeader("Content-Encoding", &content_encoding); | |
1740 std::set<std::string> used_encodings; | |
1741 if (!HttpUtil::ParseContentEncoding(content_encoding, &used_encodings)) | |
1742 return false; | |
1743 | |
1744 for (auto const& encoding : used_encodings) { | |
Randy Smith (Not in Mondays)
2017/03/21 21:23:20
This doesn't appear to handle "Accept-Encoding: *"
eustas
2017/03/27 10:27:11
Fixed.
| |
1745 if (allowed_encodings.find(encoding) == allowed_encodings.end()) | |
1746 return false; | |
1747 } | |
1748 return true; | |
1749 } | |
1750 | |
1714 } // namespace net | 1751 } // namespace net |
OLD | NEW |