| 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/tools/flip_server/spdy_interface.h" | 5 #include "net/tools/flip_server/spdy_interface.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "net/spdy/spdy_framer.h" | 10 #include "net/spdy/spdy_framer.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 132 |
| 133 SpdyHeaderBlock::const_iterator method = headers.end(); | 133 SpdyHeaderBlock::const_iterator method = headers.end(); |
| 134 SpdyHeaderBlock::const_iterator host = headers.end(); | 134 SpdyHeaderBlock::const_iterator host = headers.end(); |
| 135 SpdyHeaderBlock::const_iterator path = headers.end(); | 135 SpdyHeaderBlock::const_iterator path = headers.end(); |
| 136 SpdyHeaderBlock::const_iterator scheme = headers.end(); | 136 SpdyHeaderBlock::const_iterator scheme = headers.end(); |
| 137 SpdyHeaderBlock::const_iterator version = headers.end(); | 137 SpdyHeaderBlock::const_iterator version = headers.end(); |
| 138 SpdyHeaderBlock::const_iterator url = headers.end(); | 138 SpdyHeaderBlock::const_iterator url = headers.end(); |
| 139 | 139 |
| 140 std::string path_string, host_string, version_string; | 140 std::string path_string, host_string, version_string; |
| 141 | 141 |
| 142 if (spdy_version() == SPDY2) { | 142 method = headers.find(":method"); |
| 143 url = headers.find("url"); | 143 host = headers.find(":host"); |
| 144 method = headers.find("method"); | 144 path = headers.find(":path"); |
| 145 version = headers.find("version"); | 145 scheme = headers.find(":scheme"); |
| 146 scheme = headers.find("scheme"); | 146 if (method == headers.end() || host == headers.end() || |
| 147 if (url == headers.end() || method == headers.end() || | 147 path == headers.end() || scheme == headers.end()) { |
| 148 version == headers.end() || scheme == headers.end()) { | 148 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: A mandatory header is " |
| 149 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: A mandatory header is " | 149 << "missing. Not creating stream"; |
| 150 << "missing. Not creating stream"; | 150 return 0; |
| 151 return 0; | |
| 152 } | |
| 153 // url->second here only ever seems to contain just the path. When this | |
| 154 // path contains a query string with a http:// in one of its values, | |
| 155 // UrlUtilities::GetUrlPath will fail and always return a / breaking | |
| 156 // the request. GetUrlPath assumes the absolute URL is being passed in. | |
| 157 path_string = UrlUtilities::GetUrlPath(url->second.as_string()); | |
| 158 host_string = UrlUtilities::GetUrlHost(url->second.as_string()); | |
| 159 version_string = version->second.as_string(); | |
| 160 } else { | |
| 161 method = headers.find(":method"); | |
| 162 host = headers.find(":host"); | |
| 163 path = headers.find(":path"); | |
| 164 scheme = headers.find(":scheme"); | |
| 165 if (method == headers.end() || host == headers.end() || | |
| 166 path == headers.end() || scheme == headers.end()) { | |
| 167 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: A mandatory header is " | |
| 168 << "missing. Not creating stream"; | |
| 169 return 0; | |
| 170 } | |
| 171 host_string = host->second.as_string(); | |
| 172 path_string = path->second.as_string(); | |
| 173 version_string = "HTTP/1.1"; | |
| 174 } | 151 } |
| 152 host_string = host->second.as_string(); |
| 153 path_string = path->second.as_string(); |
| 154 version_string = "HTTP/1.1"; |
| 175 | 155 |
| 176 if (scheme->second.compare("https") == 0) { | 156 if (scheme->second.compare("https") == 0) { |
| 177 *is_https_scheme = true; | 157 *is_https_scheme = true; |
| 178 } | 158 } |
| 179 | 159 |
| 180 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_SPDY_SERVER) { | 160 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_SPDY_SERVER) { |
| 181 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Request: " << method->second | 161 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Request: " << method->second |
| 182 << " " << path_string; | 162 << " " << path_string; |
| 183 std::string filename = | 163 std::string filename = |
| 184 EncodeURL(path_string, host_string, method->second.as_string()); | 164 EncodeURL(path_string, host_string, method->second.as_string()); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 | 445 |
| 466 // These headers have no value | 446 // These headers have no value |
| 467 dest.erase("X-Associated-Content"); // TODO(mbelshe): case-sensitive | 447 dest.erase("X-Associated-Content"); // TODO(mbelshe): case-sensitive |
| 468 dest.erase("X-Original-Url"); // TODO(mbelshe): case-sensitive | 448 dest.erase("X-Original-Url"); // TODO(mbelshe): case-sensitive |
| 469 } | 449 } |
| 470 | 450 |
| 471 size_t SpdySM::SendSynStreamImpl(uint32_t stream_id, | 451 size_t SpdySM::SendSynStreamImpl(uint32_t stream_id, |
| 472 const BalsaHeaders& headers) { | 452 const BalsaHeaders& headers) { |
| 473 SpdyHeaderBlock block; | 453 SpdyHeaderBlock block; |
| 474 CopyHeaders(block, headers); | 454 CopyHeaders(block, headers); |
| 475 if (spdy_version() == SPDY2) { | 455 block[":method"] = headers.request_method().as_string(); |
| 476 block["method"] = headers.request_method().as_string(); | 456 block[":version"] = headers.request_version().as_string(); |
| 477 if (!headers.HasHeader("version")) | 457 if (headers.HasHeader("X-Original-Url")) { |
| 478 block["version"] = headers.request_version().as_string(); | 458 std::string original_url = headers.GetHeader("X-Original-Url").as_string(); |
| 479 if (headers.HasHeader("X-Original-Url")) { | 459 block[":path"] = UrlUtilities::GetUrlPath(original_url); |
| 480 std::string original_url = | 460 block[":host"] = UrlUtilities::GetUrlPath(original_url); |
| 481 headers.GetHeader("X-Original-Url").as_string(); | |
| 482 block["url"] = UrlUtilities::GetUrlPath(original_url); | |
| 483 } else { | |
| 484 block["url"] = headers.request_uri().as_string(); | |
| 485 } | |
| 486 } else { | 461 } else { |
| 487 block[":method"] = headers.request_method().as_string(); | 462 block[":path"] = headers.request_uri().as_string(); |
| 488 block[":version"] = headers.request_version().as_string(); | 463 if (block.find("host") != block.end()) { |
| 489 if (headers.HasHeader("X-Original-Url")) { | 464 block[":host"] = headers.GetHeader("Host").as_string(); |
| 490 std::string original_url = | 465 block.erase("host"); |
| 491 headers.GetHeader("X-Original-Url").as_string(); | |
| 492 block[":path"] = UrlUtilities::GetUrlPath(original_url); | |
| 493 block[":host"] = UrlUtilities::GetUrlPath(original_url); | |
| 494 } else { | |
| 495 block[":path"] = headers.request_uri().as_string(); | |
| 496 if (block.find("host") != block.end()) { | |
| 497 block[":host"] = headers.GetHeader("Host").as_string(); | |
| 498 block.erase("host"); | |
| 499 } | |
| 500 } | 466 } |
| 501 } | 467 } |
| 502 | 468 |
| 503 DCHECK(buffered_spdy_framer_); | 469 DCHECK(buffered_spdy_framer_); |
| 504 SpdyFrame* fsrcf = buffered_spdy_framer_->CreateSynStream( | 470 SpdyFrame* fsrcf = buffered_spdy_framer_->CreateSynStream( |
| 505 stream_id, 0, 0, CONTROL_FLAG_NONE, &block); | 471 stream_id, 0, 0, CONTROL_FLAG_NONE, &block); |
| 506 size_t df_size = fsrcf->size(); | 472 size_t df_size = fsrcf->size(); |
| 507 EnqueueDataFrame(new SpdyFrameDataFrame(fsrcf)); | 473 EnqueueDataFrame(new SpdyFrameDataFrame(fsrcf)); |
| 508 | 474 |
| 509 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Sending SynStreamheader " | 475 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Sending SynStreamheader " |
| 510 << stream_id; | 476 << stream_id; |
| 511 return df_size; | 477 return df_size; |
| 512 } | 478 } |
| 513 | 479 |
| 514 size_t SpdySM::SendSynReplyImpl(uint32_t stream_id, | 480 size_t SpdySM::SendSynReplyImpl(uint32_t stream_id, |
| 515 const BalsaHeaders& headers) { | 481 const BalsaHeaders& headers) { |
| 516 SpdyHeaderBlock block; | 482 SpdyHeaderBlock block; |
| 517 CopyHeaders(block, headers); | 483 CopyHeaders(block, headers); |
| 518 if (spdy_version() == SPDY2) { | 484 block[":status"] = headers.response_code().as_string() + " " + |
| 519 block["status"] = headers.response_code().as_string() + " " + | 485 headers.response_reason_phrase().as_string(); |
| 520 headers.response_reason_phrase().as_string(); | 486 block[":version"] = headers.response_version().as_string(); |
| 521 block["version"] = headers.response_version().as_string(); | |
| 522 } else { | |
| 523 block[":status"] = headers.response_code().as_string() + " " + | |
| 524 headers.response_reason_phrase().as_string(); | |
| 525 block[":version"] = headers.response_version().as_string(); | |
| 526 } | |
| 527 | 487 |
| 528 DCHECK(buffered_spdy_framer_); | 488 DCHECK(buffered_spdy_framer_); |
| 529 SpdyFrame* fsrcf = buffered_spdy_framer_->CreateSynReply( | 489 SpdyFrame* fsrcf = buffered_spdy_framer_->CreateSynReply( |
| 530 stream_id, CONTROL_FLAG_NONE, &block); | 490 stream_id, CONTROL_FLAG_NONE, &block); |
| 531 size_t df_size = fsrcf->size(); | 491 size_t df_size = fsrcf->size(); |
| 532 EnqueueDataFrame(new SpdyFrameDataFrame(fsrcf)); | 492 EnqueueDataFrame(new SpdyFrameDataFrame(fsrcf)); |
| 533 | 493 |
| 534 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Sending SynReplyheader " | 494 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Sending SynReplyheader " |
| 535 << stream_id; | 495 << stream_id; |
| 536 return df_size; | 496 return df_size; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 } | 602 } |
| 643 } | 603 } |
| 644 | 604 |
| 645 void SpdySM::CreateFramer(SpdyMajorVersion spdy_version) { | 605 void SpdySM::CreateFramer(SpdyMajorVersion spdy_version) { |
| 646 DCHECK(!buffered_spdy_framer_); | 606 DCHECK(!buffered_spdy_framer_); |
| 647 buffered_spdy_framer_.reset(new BufferedSpdyFramer(spdy_version, true)); | 607 buffered_spdy_framer_.reset(new BufferedSpdyFramer(spdy_version, true)); |
| 648 buffered_spdy_framer_->set_visitor(this); | 608 buffered_spdy_framer_->set_visitor(this); |
| 649 } | 609 } |
| 650 | 610 |
| 651 } // namespace net | 611 } // namespace net |
| OLD | NEW |