| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/websockets/websocket_basic_handshake_stream.h" | 5 #include "net/websockets/websocket_basic_handshake_stream.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 const std::vector<std::string>& value, | 120 const std::vector<std::string>& value, |
| 121 HttpRequestHeaders* headers) { | 121 HttpRequestHeaders* headers) { |
| 122 if (value.empty()) | 122 if (value.empty()) |
| 123 return; | 123 return; |
| 124 headers->SetHeader(name, JoinString(value, ", ")); | 124 headers->SetHeader(name, JoinString(value, ", ")); |
| 125 } | 125 } |
| 126 | 126 |
| 127 GetHeaderResult GetSingleHeaderValue(const HttpResponseHeaders* headers, | 127 GetHeaderResult GetSingleHeaderValue(const HttpResponseHeaders* headers, |
| 128 const base::StringPiece& name, | 128 const base::StringPiece& name, |
| 129 std::string* value) { | 129 std::string* value) { |
| 130 void* state = NULL; | 130 void* state = nullptr; |
| 131 size_t num_values = 0; | 131 size_t num_values = 0; |
| 132 std::string temp_value; | 132 std::string temp_value; |
| 133 while (headers->EnumerateHeader(&state, name, &temp_value)) { | 133 while (headers->EnumerateHeader(&state, name, &temp_value)) { |
| 134 if (++num_values > 1) | 134 if (++num_values > 1) |
| 135 return GET_HEADER_MULTIPLE; | 135 return GET_HEADER_MULTIPLE; |
| 136 *value = temp_value; | 136 *value = temp_value; |
| 137 } | 137 } |
| 138 return num_values > 0 ? GET_HEADER_OK : GET_HEADER_MISSING; | 138 return num_values > 0 ? GET_HEADER_OK : GET_HEADER_MISSING; |
| 139 } | 139 } |
| 140 | 140 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 return false; | 204 return false; |
| 205 } | 205 } |
| 206 return true; | 206 return true; |
| 207 } | 207 } |
| 208 | 208 |
| 209 bool ValidateSubProtocol( | 209 bool ValidateSubProtocol( |
| 210 const HttpResponseHeaders* headers, | 210 const HttpResponseHeaders* headers, |
| 211 const std::vector<std::string>& requested_sub_protocols, | 211 const std::vector<std::string>& requested_sub_protocols, |
| 212 std::string* sub_protocol, | 212 std::string* sub_protocol, |
| 213 std::string* failure_message) { | 213 std::string* failure_message) { |
| 214 void* state = NULL; | 214 void* state = nullptr; |
| 215 std::string value; | 215 std::string value; |
| 216 base::hash_set<std::string> requested_set(requested_sub_protocols.begin(), | 216 base::hash_set<std::string> requested_set(requested_sub_protocols.begin(), |
| 217 requested_sub_protocols.end()); | 217 requested_sub_protocols.end()); |
| 218 int count = 0; | 218 int count = 0; |
| 219 bool has_multiple_protocols = false; | 219 bool has_multiple_protocols = false; |
| 220 bool has_invalid_protocol = false; | 220 bool has_invalid_protocol = false; |
| 221 | 221 |
| 222 while (!has_invalid_protocol || !has_multiple_protocols) { | 222 while (!has_invalid_protocol || !has_multiple_protocols) { |
| 223 std::string temp_value; | 223 std::string temp_value; |
| 224 if (!headers->EnumerateHeader( | 224 if (!headers->EnumerateHeader( |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 322 } |
| 323 params->deflate_enabled = true; | 323 params->deflate_enabled = true; |
| 324 return true; | 324 return true; |
| 325 } | 325 } |
| 326 | 326 |
| 327 bool ValidateExtensions(const HttpResponseHeaders* headers, | 327 bool ValidateExtensions(const HttpResponseHeaders* headers, |
| 328 const std::vector<std::string>& requested_extensions, | 328 const std::vector<std::string>& requested_extensions, |
| 329 std::string* extensions, | 329 std::string* extensions, |
| 330 std::string* failure_message, | 330 std::string* failure_message, |
| 331 WebSocketExtensionParams* params) { | 331 WebSocketExtensionParams* params) { |
| 332 void* state = NULL; | 332 void* state = nullptr; |
| 333 std::string value; | 333 std::string value; |
| 334 std::vector<std::string> accepted_extensions; | 334 std::vector<std::string> accepted_extensions; |
| 335 // TODO(ricea): If adding support for additional extensions, generalise this | 335 // TODO(ricea): If adding support for additional extensions, generalise this |
| 336 // code. | 336 // code. |
| 337 bool seen_permessage_deflate = false; | 337 bool seen_permessage_deflate = false; |
| 338 while (headers->EnumerateHeader( | 338 while (headers->EnumerateHeader( |
| 339 &state, websockets::kSecWebSocketExtensions, &value)) { | 339 &state, websockets::kSecWebSocketExtensions, &value)) { |
| 340 WebSocketExtensionParser parser; | 340 WebSocketExtensionParser parser; |
| 341 parser.Parse(value); | 341 parser.Parse(value); |
| 342 if (parser.has_error()) { | 342 if (parser.has_error()) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 373 | 373 |
| 374 WebSocketBasicHandshakeStream::WebSocketBasicHandshakeStream( | 374 WebSocketBasicHandshakeStream::WebSocketBasicHandshakeStream( |
| 375 scoped_ptr<ClientSocketHandle> connection, | 375 scoped_ptr<ClientSocketHandle> connection, |
| 376 WebSocketStream::ConnectDelegate* connect_delegate, | 376 WebSocketStream::ConnectDelegate* connect_delegate, |
| 377 bool using_proxy, | 377 bool using_proxy, |
| 378 std::vector<std::string> requested_sub_protocols, | 378 std::vector<std::string> requested_sub_protocols, |
| 379 std::vector<std::string> requested_extensions, | 379 std::vector<std::string> requested_extensions, |
| 380 std::string* failure_message) | 380 std::string* failure_message) |
| 381 : state_(connection.release(), using_proxy), | 381 : state_(connection.release(), using_proxy), |
| 382 connect_delegate_(connect_delegate), | 382 connect_delegate_(connect_delegate), |
| 383 http_response_info_(NULL), | 383 http_response_info_(nullptr), |
| 384 requested_sub_protocols_(requested_sub_protocols), | 384 requested_sub_protocols_(requested_sub_protocols), |
| 385 requested_extensions_(requested_extensions), | 385 requested_extensions_(requested_extensions), |
| 386 failure_message_(failure_message) { | 386 failure_message_(failure_message) { |
| 387 DCHECK(connect_delegate); | 387 DCHECK(connect_delegate); |
| 388 DCHECK(failure_message); | 388 DCHECK(failure_message); |
| 389 } | 389 } |
| 390 | 390 |
| 391 WebSocketBasicHandshakeStream::~WebSocketBasicHandshakeStream() {} | 391 WebSocketBasicHandshakeStream::~WebSocketBasicHandshakeStream() {} |
| 392 | 392 |
| 393 int WebSocketBasicHandshakeStream::InitializeStream( | 393 int WebSocketBasicHandshakeStream::InitializeStream( |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 HttpResponseBodyDrainer* drainer = new HttpResponseBodyDrainer(this); | 523 HttpResponseBodyDrainer* drainer = new HttpResponseBodyDrainer(this); |
| 524 drainer->Start(session); | 524 drainer->Start(session); |
| 525 // |drainer| will delete itself. | 525 // |drainer| will delete itself. |
| 526 } | 526 } |
| 527 | 527 |
| 528 void WebSocketBasicHandshakeStream::SetPriority(RequestPriority priority) { | 528 void WebSocketBasicHandshakeStream::SetPriority(RequestPriority priority) { |
| 529 // TODO(ricea): See TODO comment in HttpBasicStream::SetPriority(). If it is | 529 // TODO(ricea): See TODO comment in HttpBasicStream::SetPriority(). If it is |
| 530 // gone, then copy whatever has happened there over here. | 530 // gone, then copy whatever has happened there over here. |
| 531 } | 531 } |
| 532 | 532 |
| 533 UploadProgress WebSocketBasicHandshakeStream::GetUploadProgress() const { |
| 534 return UploadProgress(); |
| 535 } |
| 536 |
| 537 HttpStream* WebSocketBasicHandshakeStream::RenewStreamForAuth() { |
| 538 // Return null because we don't support renewing the stream. |
| 539 return nullptr; |
| 540 } |
| 541 |
| 533 scoped_ptr<WebSocketStream> WebSocketBasicHandshakeStream::Upgrade() { | 542 scoped_ptr<WebSocketStream> WebSocketBasicHandshakeStream::Upgrade() { |
| 534 // The HttpStreamParser object has a pointer to our ClientSocketHandle. Make | 543 // The HttpStreamParser object has a pointer to our ClientSocketHandle. Make |
| 535 // sure it does not touch it again before it is destroyed. | 544 // sure it does not touch it again before it is destroyed. |
| 536 state_.DeleteParser(); | 545 state_.DeleteParser(); |
| 537 WebSocketTransportClientSocketPool::UnlockEndpoint(state_.connection()); | 546 WebSocketTransportClientSocketPool::UnlockEndpoint(state_.connection()); |
| 538 scoped_ptr<WebSocketStream> basic_stream( | 547 scoped_ptr<WebSocketStream> basic_stream( |
| 539 new WebSocketBasicStream(state_.ReleaseConnection(), | 548 new WebSocketBasicStream(state_.ReleaseConnection(), |
| 540 state_.read_buf(), | 549 state_.read_buf(), |
| 541 sub_protocol_, | 550 sub_protocol_, |
| 542 extensions_)); | 551 extensions_)); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 set_failure_message("Error during WebSocket handshake: " + failure_message); | 679 set_failure_message("Error during WebSocket handshake: " + failure_message); |
| 671 return ERR_INVALID_RESPONSE; | 680 return ERR_INVALID_RESPONSE; |
| 672 } | 681 } |
| 673 | 682 |
| 674 void WebSocketBasicHandshakeStream::set_failure_message( | 683 void WebSocketBasicHandshakeStream::set_failure_message( |
| 675 const std::string& failure_message) { | 684 const std::string& failure_message) { |
| 676 *failure_message_ = failure_message; | 685 *failure_message_ = failure_message; |
| 677 } | 686 } |
| 678 | 687 |
| 679 } // namespace net | 688 } // namespace net |
| OLD | NEW |