Chromium Code Reviews| 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/server/web_socket.h" | 5 #include "net/server/web_socket.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 server_->SendRaw(connection_->id(), | 93 server_->SendRaw(connection_->id(), |
| 94 ValidResponseString(encoded_hash, response_extensions)); | 94 ValidResponseString(encoded_hash, response_extensions)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 WebSocket::ParseResult WebSocket::Read(std::string* message) { | 97 WebSocket::ParseResult WebSocket::Read(std::string* message) { |
| 98 if (closed_) | 98 if (closed_) |
| 99 return FRAME_CLOSE; | 99 return FRAME_CLOSE; |
| 100 | 100 |
| 101 if (!encoder_) { | |
| 102 // RFC6455, section 4.1 says "Once the client's opening handshake has been | |
| 103 // sent, the client MUST wait for a response from the server before sending | |
| 104 // any further data". If encoder_ is null here, we haven't even sent a | |
|
mmenke
2017/01/23 16:17:21
nit (x2): |encoder_| is the more common pattern i
Maks Orlovich
2017/01/23 17:28:29
Done. I incorrectly assumed this was just for API
| |
| 105 // server handshake in the first place, so the client clearly didn't do | |
| 106 // that, so we can reject them guilt-free, especially since we can't | |
|
mmenke
2017/01/23 16:17:21
nit (x2): Avoid we in comments, due to ambiguity.
Maks Orlovich
2017/01/23 17:28:29
Rephrased.
| |
| 107 // proceed without an encoder_ anyway. | |
| 108 Fail(); | |
|
mmenke
2017/01/23 16:17:21
Hrm...The caller already closes the socket when we
Maks Orlovich
2017/01/23 17:28:29
Good point, done. This does mean we don't set clos
| |
| 109 return FRAME_CLOSE; | |
|
mmenke
2017/01/23 16:17:21
FRAME_ERROR seems more accurate.
Maks Orlovich
2017/01/23 17:28:29
Done.
| |
| 110 } | |
| 111 | |
| 101 HttpConnection::ReadIOBuffer* read_buf = connection_->read_buf(); | 112 HttpConnection::ReadIOBuffer* read_buf = connection_->read_buf(); |
| 102 base::StringPiece frame(read_buf->StartOfBuffer(), read_buf->GetSize()); | 113 base::StringPiece frame(read_buf->StartOfBuffer(), read_buf->GetSize()); |
| 103 int bytes_consumed = 0; | 114 int bytes_consumed = 0; |
| 104 ParseResult result = encoder_->DecodeFrame(frame, &bytes_consumed, message); | 115 ParseResult result = encoder_->DecodeFrame(frame, &bytes_consumed, message); |
| 105 if (result == FRAME_OK) | 116 if (result == FRAME_OK) |
| 106 read_buf->DidConsume(bytes_consumed); | 117 read_buf->DidConsume(bytes_consumed); |
| 107 if (result == FRAME_CLOSE) | 118 if (result == FRAME_CLOSE) |
| 108 closed_ = true; | 119 closed_ = true; |
| 109 return result; | 120 return result; |
| 110 } | 121 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 124 } | 135 } |
| 125 | 136 |
| 126 void WebSocket::SendErrorResponse(const std::string& message) { | 137 void WebSocket::SendErrorResponse(const std::string& message) { |
| 127 if (closed_) | 138 if (closed_) |
| 128 return; | 139 return; |
| 129 closed_ = true; | 140 closed_ = true; |
| 130 server_->Send500(connection_->id(), message); | 141 server_->Send500(connection_->id(), message); |
| 131 } | 142 } |
| 132 | 143 |
| 133 } // namespace net | 144 } // namespace net |
| OLD | NEW |