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

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 2642723008: Allow proxying plaintext websockets over http/2 proxy (Closed)
Patch Set: Fix review nits Created 3 years, 11 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/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 16495 matching lines...) Expand 10 before | Expand all | Expand 10 after
16506 trans.Start(&request, callback.callback(), NetLogWithSource())); 16506 trans.Start(&request, callback.callback(), NetLogWithSource()));
16507 base::RunLoop().RunUntilIdle(); 16507 base::RunLoop().RunUntilIdle();
16508 16508
16509 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); 16509 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy);
16510 HttpRequestHeaders headers; 16510 HttpRequestHeaders headers;
16511 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); 16511 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers));
16512 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); 16512 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding));
16513 } 16513 }
16514 #endif // !defined(OS_IOS) 16514 #endif // !defined(OS_IOS)
16515 16515
16516 // Test a SPDY CONNECT through an HTTPS Proxy to plaintext WebSocket Server.
16517 TEST_F(HttpNetworkTransactionTest, PlaintextWebsocketOverSpdyProxy) {
16518 HttpRequestInfo request;
16519 request.method = "GET";
16520 request.url = GURL("ws://www.example.org/");
16521 AddWebSocketHeaders(&request.extra_headers);
16522
16523 // Configure against https proxy server "proxy:70".
16524 session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70");
16525 BoundTestNetLog log;
16526 session_deps_.net_log = log.bound().net_log();
16527 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
16528
16529 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
16530 FakeWebSocketStreamCreateHelper websocket_stream_create_helper;
16531 trans.SetWebSocketHandshakeStreamCreateHelper(
16532 &websocket_stream_create_helper);
16533
16534 // CONNECT to www.example.org:443 via SPDY
16535 SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect(
16536 NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 80)));
Bence 2017/01/24 22:54:19 Please use nullptr instead of NULL in new code, he
baranovich 2017/01/25 09:10:51 Done.
16537 const char req[] =
16538 "GET / HTTP/1.1\r\n"
16539 "Host: www.example.org\r\n"
16540 "Connection: Upgrade\r\n"
16541 "Upgrade: websocket\r\n"
16542 "Origin: http://www.example.org\r\n"
16543 "Sec-WebSocket-Version: 13\r\n"
16544 "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n";
16545 SpdySerializedFrame wrapped_ws_req(
16546 spdy_util_.ConstructSpdyDataFrame(1, req, strlen(req), false));
16547 SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1));
16548 const char resp[] =
16549 "HTTP/1.1 101 Switching Protocols\r\n"
16550 "Upgrade: websocket\r\n"
16551 "Connection: Upgrade\r\n"
16552 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n";
16553 SpdySerializedFrame wrapped_ws_resp(
16554 spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false));
16555 SpdySerializedFrame window_update(
16556 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_ws_resp.size()));
16557
16558 MockWrite spdy_writes[] = {
16559 CreateMockWrite(connect, 0), CreateMockWrite(wrapped_ws_req, 2),
16560 CreateMockWrite(window_update, 4),
16561 };
16562
16563 MockRead spdy_reads[] = {
16564 CreateMockRead(conn_resp, 1, ASYNC),
16565 CreateMockRead(wrapped_ws_resp, 3, ASYNC), MockRead(ASYNC, 0, 5),
16566 };
16567
16568 SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes,
16569 arraysize(spdy_writes));
16570 session_deps_.socket_factory->AddSocketDataProvider(&spdy_data);
16571
16572 SSLSocketDataProvider ssl(ASYNC, OK);
16573 ssl.next_proto = kProtoHTTP2;
16574 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
16575
16576 TestCompletionCallback callback;
16577
16578 int rv = trans.Start(&request, callback.callback(), log.bound());
16579 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
16580
16581 rv = callback.WaitForResult();
16582 ASSERT_THAT(rv, IsOk());
16583
16584 const HttpResponseInfo* response = trans.GetResponseInfo();
16585 ASSERT_TRUE(response);
16586 ASSERT_TRUE(response->headers);
16587 EXPECT_EQ("HTTP/1.1 101 Switching Protocols",
16588 response->headers->GetStatusLine());
16589 }
16590
16516 } // namespace net 16591 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_stream_factory_impl_job.cc » ('j') | net/http/http_stream_factory_impl_job.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698