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

Side by Side Diff: net/websockets/websocket_test_util.cc

Issue 2003253002: [Devtools] Allow User-Agent header override for Websockets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tests Created 4 years, 5 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
OLDNEW
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_test_util.h" 5 #include "net/websockets/websocket_test_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 16 matching lines...) Expand all
27 27
28 LinearCongruentialGenerator::LinearCongruentialGenerator(uint32_t seed) 28 LinearCongruentialGenerator::LinearCongruentialGenerator(uint32_t seed)
29 : current_(seed) {} 29 : current_(seed) {}
30 30
31 uint32_t LinearCongruentialGenerator::Generate() { 31 uint32_t LinearCongruentialGenerator::Generate() {
32 uint64_t result = current_; 32 uint64_t result = current_;
33 current_ = (current_ * kA + kC) % kM; 33 current_ = (current_ * kA + kC) % kM;
34 return static_cast<uint32_t>(result >> 16); 34 return static_cast<uint32_t>(result >> 16);
35 } 35 }
36 36
37 std::string WebSocketStandardRequest(const std::string& path, 37 std::string WebSocketStandardRequest(
38 const std::string& host, 38 const std::string& path,
39 const url::Origin& origin, 39 const std::string& host,
40 const std::string& extra_headers) { 40 const url::Origin& origin,
41 const std::string& send_additional_request_headers,
42 const std::string& extra_headers) {
41 return WebSocketStandardRequestWithCookies(path, host, origin, std::string(), 43 return WebSocketStandardRequestWithCookies(path, host, origin, std::string(),
44 send_additional_request_headers,
42 extra_headers); 45 extra_headers);
43 } 46 }
44 47
45 std::string WebSocketStandardRequestWithCookies( 48 std::string WebSocketStandardRequestWithCookies(
46 const std::string& path, 49 const std::string& path,
47 const std::string& host, 50 const std::string& host,
48 const url::Origin& origin, 51 const url::Origin& origin,
49 const std::string& cookies, 52 const std::string& cookies,
53 const std::string& send_additional_request_headers,
50 const std::string& extra_headers) { 54 const std::string& extra_headers) {
51 // Unrelated changes in net/http may change the order and default-values of 55 // Unrelated changes in net/http may change the order and default-values of
52 // HTTP headers, causing WebSocket tests to fail. It is safe to update this 56 // HTTP headers, causing WebSocket tests to fail. It is safe to update this
53 // string in that case. 57 // in that case.
54 return base::StringPrintf( 58 HttpRequestHeaders headers;
55 "GET %s HTTP/1.1\r\n" 59 std::stringstream request_headers;
56 "Host: %s\r\n" 60
57 "Connection: Upgrade\r\n" 61 request_headers << base::StringPrintf("GET %s HTTP/1.1\r\n", path.c_str());
58 "Pragma: no-cache\r\n" 62 headers.SetHeader("Host", host);
59 "Cache-Control: no-cache\r\n" 63 headers.SetHeader("Connection", "Upgrade");
60 "Upgrade: websocket\r\n" 64 headers.SetHeader("Pragma", "no-cache");
61 "Origin: %s\r\n" 65 headers.SetHeader("Cache-Control", "no-cache");
62 "Sec-WebSocket-Version: 13\r\n" 66 headers.SetHeader("Upgrade", "websocket");
63 "User-Agent:\r\n" 67 headers.SetHeader("Origin", origin.Serialize());
64 "Accept-Encoding: gzip, deflate\r\n" 68 headers.SetHeader("Sec-WebSocket-Version", "13");
65 "Accept-Language: en-us,fr\r\n" 69 headers.SetHeader("User-Agent", "");
66 "%s" 70 headers.AddHeadersFromString(send_additional_request_headers);
67 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" 71 headers.SetHeader("Accept-Encoding", "gzip, deflate");
68 "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n" 72 headers.SetHeader("Accept-Language", "en-us,fr");
69 "%s\r\n", 73 headers.AddHeadersFromString(cookies);
70 path.c_str(), host.c_str(), origin.Serialize().c_str(), cookies.c_str(), 74 headers.SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==");
71 extra_headers.c_str()); 75 headers.SetHeader("Sec-WebSocket-Extensions",
76 "permessage-deflate; client_max_window_bits");
77 headers.AddHeadersFromString(extra_headers);
78
79 request_headers << headers.ToString();
80 return request_headers.str();
72 } 81 }
73 82
74 std::string WebSocketStandardResponse(const std::string& extra_headers) { 83 std::string WebSocketStandardResponse(const std::string& extra_headers) {
75 return base::StringPrintf( 84 return base::StringPrintf(
76 "HTTP/1.1 101 Switching Protocols\r\n" 85 "HTTP/1.1 101 Switching Protocols\r\n"
77 "Upgrade: websocket\r\n" 86 "Upgrade: websocket\r\n"
78 "Connection: Upgrade\r\n" 87 "Connection: Upgrade\r\n"
79 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" 88 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n"
80 "%s\r\n", 89 "%s\r\n",
81 extra_headers.c_str()); 90 extra_headers.c_str());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (!url_request_context_initialized_) { 181 if (!url_request_context_initialized_) {
173 url_request_context_.Init(); 182 url_request_context_.Init();
174 // A Network Delegate is required to make the URLRequest::Delegate work. 183 // A Network Delegate is required to make the URLRequest::Delegate work.
175 url_request_context_.set_network_delegate(&network_delegate_); 184 url_request_context_.set_network_delegate(&network_delegate_);
176 url_request_context_initialized_ = true; 185 url_request_context_initialized_ = true;
177 } 186 }
178 return &url_request_context_; 187 return &url_request_context_;
179 } 188 }
180 189
181 } // namespace net 190 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698