Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Side by Side Diff: net/server/web_socket.cc

Issue 1357693003: Returning scoped_ptr<> instead of raw pointer in WebSocket::CreateWebSocket (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/server/web_socket.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/base64.h" 7 #include "base/base64.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/sha1.h" 9 #include "base/sha1.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 16 matching lines...) Expand all
27 encoder_.reset(WebSocketEncoder::CreateServer(request_extensions, 27 encoder_.reset(WebSocketEncoder::CreateServer(request_extensions,
28 &response_extensions_)); 28 &response_extensions_));
29 if (!response_extensions_.empty()) { 29 if (!response_extensions_.empty()) {
30 response_extensions_ = 30 response_extensions_ =
31 "Sec-WebSocket-Extensions: " + response_extensions_ + "\r\n"; 31 "Sec-WebSocket-Extensions: " + response_extensions_ + "\r\n";
32 } 32 }
33 } 33 }
34 34
35 WebSocket::~WebSocket() {} 35 WebSocket::~WebSocket() {}
36 36
37 WebSocket* WebSocket::CreateWebSocket(HttpServer* server, 37 scoped_ptr<WebSocket> WebSocket::CreateWebSocket(
38 HttpConnection* connection, 38 HttpServer* server,
39 const HttpServerRequestInfo& request) { 39 HttpConnection* connection,
40 const HttpServerRequestInfo& request) {
40 std::string version = request.GetHeaderValue("sec-websocket-version"); 41 std::string version = request.GetHeaderValue("sec-websocket-version");
41 if (version != "8" && version != "13") { 42 if (version != "8" && version != "13") {
42 server->SendResponse( 43 server->SendResponse(
43 connection->id(), 44 connection->id(),
44 HttpServerResponseInfo::CreateFor500( 45 HttpServerResponseInfo::CreateFor500(
45 "Invalid request format. The version is not valid.")); 46 "Invalid request format. The version is not valid."));
46 return nullptr; 47 return nullptr;
47 } 48 }
48 49
49 std::string key = request.GetHeaderValue("sec-websocket-key"); 50 std::string key = request.GetHeaderValue("sec-websocket-key");
50 if (key.empty()) { 51 if (key.empty()) {
51 server->SendResponse( 52 server->SendResponse(
52 connection->id(), 53 connection->id(),
53 HttpServerResponseInfo::CreateFor500( 54 HttpServerResponseInfo::CreateFor500(
54 "Invalid request format. Sec-WebSocket-Key is empty or isn't " 55 "Invalid request format. Sec-WebSocket-Key is empty or isn't "
55 "specified.")); 56 "specified."));
56 return nullptr; 57 return nullptr;
57 } 58 }
58 return new WebSocket(server, connection, request); 59 return make_scoped_ptr(new WebSocket(server, connection, request));
59 } 60 }
60 61
61 void WebSocket::Accept(const HttpServerRequestInfo& request) { 62 void WebSocket::Accept(const HttpServerRequestInfo& request) {
62 static const char* const kWebSocketGuid = 63 static const char* const kWebSocketGuid =
63 "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; 64 "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
64 std::string key = request.GetHeaderValue("sec-websocket-key"); 65 std::string key = request.GetHeaderValue("sec-websocket-key");
65 std::string data = base::StringPrintf("%s%s", key.c_str(), kWebSocketGuid); 66 std::string data = base::StringPrintf("%s%s", key.c_str(), kWebSocketGuid);
66 std::string encoded_hash; 67 std::string encoded_hash;
67 base::Base64Encode(base::SHA1HashString(data), &encoded_hash); 68 base::Base64Encode(base::SHA1HashString(data), &encoded_hash);
68 69
(...skipping 22 matching lines...) Expand all
91 92
92 void WebSocket::Send(const std::string& message) { 93 void WebSocket::Send(const std::string& message) {
93 if (closed_) 94 if (closed_)
94 return; 95 return;
95 std::string encoded; 96 std::string encoded;
96 encoder_->EncodeFrame(message, 0, &encoded); 97 encoder_->EncodeFrame(message, 0, &encoded);
97 server_->SendRaw(connection_->id(), encoded); 98 server_->SendRaw(connection_->id(), encoded);
98 } 99 }
99 100
100 } // namespace net 101 } // namespace net
OLDNEW
« no previous file with comments | « net/server/web_socket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698