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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/base64.h" | 13 #include "base/base64.h" |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/containers/hash_tables.h" | 16 #include "base/containers/hash_tables.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/metrics/sparse_histogram.h" |
18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_piece.h" | 21 #include "base/strings/string_piece.h" |
21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
22 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
23 #include "base/time/time.h" | 24 #include "base/time/time.h" |
24 #include "crypto/random.h" | 25 #include "crypto/random.h" |
25 #include "net/http/http_request_headers.h" | 26 #include "net/http/http_request_headers.h" |
26 #include "net/http/http_request_info.h" | 27 #include "net/http/http_request_info.h" |
27 #include "net/http/http_response_body_drainer.h" | 28 #include "net/http/http_response_body_drainer.h" |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 headers->response_code(), | 546 headers->response_code(), |
546 headers->GetStatusText(), | 547 headers->GetStatusText(), |
547 headers, | 548 headers, |
548 http_response_info_->response_time)); | 549 http_response_info_->response_time)); |
549 connect_delegate_->OnFinishOpeningHandshake(response.Pass()); | 550 connect_delegate_->OnFinishOpeningHandshake(response.Pass()); |
550 } | 551 } |
551 } | 552 } |
552 | 553 |
553 int WebSocketBasicHandshakeStream::ValidateResponse(int rv) { | 554 int WebSocketBasicHandshakeStream::ValidateResponse(int rv) { |
554 DCHECK(http_response_info_); | 555 DCHECK(http_response_info_); |
555 const HttpResponseHeaders* headers = http_response_info_->headers.get(); | 556 // Most net errors happen during connection, so they are not seen by this |
| 557 // method. The histogram for error codes is created in |
| 558 // Delegate::OnResponseStarted in websocket_stream.cc instead. |
556 if (rv >= 0) { | 559 if (rv >= 0) { |
557 switch (headers->response_code()) { | 560 const HttpResponseHeaders* headers = http_response_info_->headers.get(); |
| 561 const int response_code = headers->response_code(); |
| 562 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.WebSocket.ResponseCode", response_code); |
| 563 switch (response_code) { |
558 case HTTP_SWITCHING_PROTOCOLS: | 564 case HTTP_SWITCHING_PROTOCOLS: |
559 OnFinishOpeningHandshake(); | 565 OnFinishOpeningHandshake(); |
560 return ValidateUpgradeResponse(headers); | 566 return ValidateUpgradeResponse(headers); |
561 | 567 |
562 // We need to pass these through for authentication to work. | 568 // We need to pass these through for authentication to work. |
563 case HTTP_UNAUTHORIZED: | 569 case HTTP_UNAUTHORIZED: |
564 case HTTP_PROXY_AUTHENTICATION_REQUIRED: | 570 case HTTP_PROXY_AUTHENTICATION_REQUIRED: |
565 return OK; | 571 return OK; |
566 | 572 |
567 // Other status codes are potentially risky (see the warnings in the | 573 // Other status codes are potentially risky (see the warnings in the |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 &extensions_, | 618 &extensions_, |
613 &failure_message_, | 619 &failure_message_, |
614 extension_params_.get())) { | 620 extension_params_.get())) { |
615 return OK; | 621 return OK; |
616 } | 622 } |
617 failure_message_ = "Error during WebSocket handshake: " + failure_message_; | 623 failure_message_ = "Error during WebSocket handshake: " + failure_message_; |
618 return ERR_INVALID_RESPONSE; | 624 return ERR_INVALID_RESPONSE; |
619 } | 625 } |
620 | 626 |
621 } // namespace net | 627 } // namespace net |
OLD | NEW |