| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/field_trial.h" | 9 #include "base/field_trial.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 // required yet. | 234 // required yet. |
| 235 bool has_auth_identity = | 235 bool has_auth_identity = |
| 236 auth_identity_[target].source != HttpAuth::IDENT_SRC_NONE; | 236 auth_identity_[target].source != HttpAuth::IDENT_SRC_NONE; |
| 237 if (has_auth_identity) { | 237 if (has_auth_identity) { |
| 238 session_->auth_cache()->Add(AuthOrigin(target), auth_handler_[target], | 238 session_->auth_cache()->Add(AuthOrigin(target), auth_handler_[target], |
| 239 auth_identity_[target].username, auth_identity_[target].password, | 239 auth_identity_[target].username, auth_identity_[target].password, |
| 240 AuthPath(target)); | 240 AuthPath(target)); |
| 241 } | 241 } |
| 242 | 242 |
| 243 bool keep_alive = false; | 243 bool keep_alive = false; |
| 244 // If the auth scheme is connection-based but the proxy/server mistakenly | 244 if (response_.headers->IsKeepAlive()) { |
| 245 // marks the connection as non-keep-alive, we still keep it alive. | |
| 246 if (response_.headers->IsKeepAlive() || | |
| 247 (auth_handler_[target]->is_connection_based() && has_auth_identity)) { | |
| 248 // If there is a response body of known length, we need to drain it first. | 245 // If there is a response body of known length, we need to drain it first. |
| 249 if (response_body_length_ > 0 || chunked_decoder_.get()) { | 246 if (response_body_length_ > 0 || chunked_decoder_.get()) { |
| 250 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART; | 247 next_state_ = STATE_DRAIN_BODY_FOR_AUTH_RESTART; |
| 251 read_buf_ = new IOBuffer(kDrainBodyBufferSize); // A bit bucket | 248 read_buf_ = new IOBuffer(kDrainBodyBufferSize); // A bit bucket |
| 252 read_buf_len_ = kDrainBodyBufferSize; | 249 read_buf_len_ = kDrainBodyBufferSize; |
| 253 return; | 250 return; |
| 254 } | 251 } |
| 255 if (response_body_length_ == 0) // No response body to drain. | 252 if (response_body_length_ == 0) // No response body to drain. |
| 256 keep_alive = true; | 253 keep_alive = true; |
| 257 // response_body_length_ is -1 and we're not using chunked encoding. We | 254 // response_body_length_ is -1 and we're not using chunked encoding. We |
| 258 // don't know the length of the response body, so we can't reuse this | 255 // don't know the length of the response body, so we can't reuse this |
| 259 // connection even though the server says it's keep-alive or we need to | 256 // connection even though the server says it's keep-alive. |
| 260 // keep it alive for authentication. | 257 } |
| 258 |
| 259 // If the auth scheme is connection-based but the proxy/server mistakenly |
| 260 // marks the connection as non-keep-alive, the auth is going to fail, so log |
| 261 // an error message. |
| 262 if (!keep_alive && auth_handler_[target]->is_connection_based() && |
| 263 has_auth_identity) { |
| 264 LOG(ERROR) << "Can't perform " << auth_handler_[target]->scheme() |
| 265 << " auth to the " << AuthTargetString(target) << " " |
| 266 << AuthOrigin(target) << " over a non-keep-alive connection"; |
| 267 |
| 268 HttpVersion http_version = response_.headers->GetHttpVersion(); |
| 269 LOG(ERROR) << " HTTP version is " << http_version.major_value() << "." |
| 270 << http_version.minor_value(); |
| 271 |
| 272 std::string header_val; |
| 273 void* iter = NULL; |
| 274 while (response_.headers->EnumerateHeader(&iter, "connection", |
| 275 &header_val)) { |
| 276 LOG(ERROR) << " Has header Connection: " << header_val; |
| 277 } |
| 278 |
| 279 iter = NULL; |
| 280 while (response_.headers->EnumerateHeader(&iter, "proxy-connection", |
| 281 &header_val)) { |
| 282 LOG(ERROR) << " Has header Proxy-Connection: " << header_val; |
| 283 } |
| 284 |
| 285 // RFC 4559 requires that a proxy indicate its support of NTLM/Negotiate |
| 286 // authentication with a "Proxy-Support: Session-Based-Authentication" |
| 287 // response header. |
| 288 iter = NULL; |
| 289 while (response_.headers->EnumerateHeader(&iter, "proxy-support", |
| 290 &header_val)) { |
| 291 LOG(ERROR) << " Has header Proxy-Support: " << header_val; |
| 292 } |
| 261 } | 293 } |
| 262 | 294 |
| 263 // We don't need to drain the response body, so we act as if we had drained | 295 // We don't need to drain the response body, so we act as if we had drained |
| 264 // the response body. | 296 // the response body. |
| 265 DidDrainBodyForAuthRestart(keep_alive); | 297 DidDrainBodyForAuthRestart(keep_alive); |
| 266 } | 298 } |
| 267 | 299 |
| 268 void HttpNetworkTransaction::DidDrainBodyForAuthRestart(bool keep_alive) { | 300 void HttpNetworkTransaction::DidDrainBodyForAuthRestart(bool keep_alive) { |
| 269 if (keep_alive) { | 301 if (keep_alive) { |
| 270 next_state_ = STATE_WRITE_HEADERS; | 302 next_state_ = STATE_WRITE_HEADERS; |
| (...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 host_and_port = proxy_info_.proxy_server().host_and_port(); | 1611 host_and_port = proxy_info_.proxy_server().host_and_port(); |
| 1580 } else { | 1612 } else { |
| 1581 DCHECK(target == HttpAuth::AUTH_SERVER); | 1613 DCHECK(target == HttpAuth::AUTH_SERVER); |
| 1582 host_and_port = GetHostAndPort(request_->url); | 1614 host_and_port = GetHostAndPort(request_->url); |
| 1583 } | 1615 } |
| 1584 auth_info->host_and_port = ASCIIToWide(host_and_port); | 1616 auth_info->host_and_port = ASCIIToWide(host_and_port); |
| 1585 response_.auth_challenge = auth_info; | 1617 response_.auth_challenge = auth_info; |
| 1586 } | 1618 } |
| 1587 | 1619 |
| 1588 } // namespace net | 1620 } // namespace net |
| OLD | NEW |