| 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" |
| 11 #include "net/spdy/spdy_protocol.h" | 11 #include "net/spdy/spdy_protocol.h" |
| 12 #include "net/tools/dump_cache/url_utilities.h" | 12 #include "net/tools/dump_cache/url_utilities.h" |
| 13 #include "net/tools/flip_server/constants.h" | 13 #include "net/tools/flip_server/constants.h" |
| 14 #include "net/tools/flip_server/flip_config.h" | 14 #include "net/tools/flip_server/flip_config.h" |
| 15 #include "net/tools/flip_server/http_interface.h" | 15 #include "net/tools/flip_server/http_interface.h" |
| 16 #include "net/tools/flip_server/spdy_util.h" | 16 #include "net/tools/flip_server/spdy_util.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 std::string SpdySM::forward_ip_header_; | 21 std::string SpdySM::forward_ip_header_; |
| 22 | 22 |
| 23 class SpdyFrameDataFrame : public DataFrame { | 23 class SpdyFrameDataFrame : public DataFrame { |
| 24 public: | 24 public: |
| 25 explicit SpdyFrameDataFrame(SpdyFrame* spdy_frame) | 25 explicit SpdyFrameDataFrame(SpdyFrame* spdy_frame) : frame(spdy_frame) { |
| 26 : frame(spdy_frame) { | |
| 27 data = spdy_frame->data(); | 26 data = spdy_frame->data(); |
| 28 size = spdy_frame->size(); | 27 size = spdy_frame->size(); |
| 29 } | 28 } |
| 30 | 29 |
| 31 virtual ~SpdyFrameDataFrame() { | 30 virtual ~SpdyFrameDataFrame() { delete frame; } |
| 32 delete frame; | |
| 33 } | |
| 34 | 31 |
| 35 const SpdyFrame* frame; | 32 const SpdyFrame* frame; |
| 36 }; | 33 }; |
| 37 | 34 |
| 38 SpdySM::SpdySM(SMConnection* connection, | 35 SpdySM::SpdySM(SMConnection* connection, |
| 39 SMInterface* sm_http_interface, | 36 SMInterface* sm_http_interface, |
| 40 EpollServer* epoll_server, | 37 EpollServer* epoll_server, |
| 41 MemoryCache* memory_cache, | 38 MemoryCache* memory_cache, |
| 42 FlipAcceptor* acceptor, | 39 FlipAcceptor* acceptor, |
| 43 SpdyMajorVersion spdy_version) | 40 SpdyMajorVersion spdy_version) |
| 44 : buffered_spdy_framer_(new BufferedSpdyFramer(spdy_version, true)), | 41 : buffered_spdy_framer_(new BufferedSpdyFramer(spdy_version, true)), |
| 45 valid_spdy_session_(false), | 42 valid_spdy_session_(false), |
| 46 connection_(connection), | 43 connection_(connection), |
| 47 client_output_list_(connection->output_list()), | 44 client_output_list_(connection->output_list()), |
| 48 client_output_ordering_(connection), | 45 client_output_ordering_(connection), |
| 49 next_outgoing_stream_id_(2), | 46 next_outgoing_stream_id_(2), |
| 50 epoll_server_(epoll_server), | 47 epoll_server_(epoll_server), |
| 51 acceptor_(acceptor), | 48 acceptor_(acceptor), |
| 52 memory_cache_(memory_cache), | 49 memory_cache_(memory_cache), |
| 53 close_on_error_(false) { | 50 close_on_error_(false) { |
| 54 buffered_spdy_framer_->set_visitor(this); | 51 buffered_spdy_framer_->set_visitor(this); |
| 55 } | 52 } |
| 56 | 53 |
| 57 SpdySM::~SpdySM() { | 54 SpdySM::~SpdySM() { delete buffered_spdy_framer_; } |
| 58 delete buffered_spdy_framer_; | |
| 59 } | |
| 60 | 55 |
| 61 void SpdySM::InitSMConnection(SMConnectionPoolInterface* connection_pool, | 56 void SpdySM::InitSMConnection(SMConnectionPoolInterface* connection_pool, |
| 62 SMInterface* sm_interface, | 57 SMInterface* sm_interface, |
| 63 EpollServer* epoll_server, | 58 EpollServer* epoll_server, |
| 64 int fd, | 59 int fd, |
| 65 std::string server_ip, | 60 std::string server_ip, |
| 66 std::string server_port, | 61 std::string server_port, |
| 67 std::string remote_ip, | 62 std::string remote_ip, |
| 68 bool use_ssl) { | 63 bool use_ssl) { |
| 69 VLOG(2) << ACCEPTOR_CLIENT_IDENT | 64 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Initializing server connection."; |
| 70 << "SpdySM: Initializing server connection."; | 65 connection_->InitSMConnection(connection_pool, |
| 71 connection_->InitSMConnection(connection_pool, sm_interface, | 66 sm_interface, |
| 72 epoll_server, fd, server_ip, server_port, | 67 epoll_server, |
| 73 remote_ip, use_ssl); | 68 fd, |
| 69 server_ip, |
| 70 server_port, |
| 71 remote_ip, |
| 72 use_ssl); |
| 74 } | 73 } |
| 75 | 74 |
| 76 SMInterface* SpdySM::NewConnectionInterface() { | 75 SMInterface* SpdySM::NewConnectionInterface() { |
| 77 SMConnection* server_connection = | 76 SMConnection* server_connection = |
| 78 SMConnection::NewSMConnection(epoll_server_, | 77 SMConnection::NewSMConnection(epoll_server_, |
| 79 NULL, | 78 NULL, |
| 80 memory_cache_, | 79 memory_cache_, |
| 81 acceptor_, | 80 acceptor_, |
| 82 "http_conn: "); | 81 "http_conn: "); |
| 83 if (server_connection == NULL) { | 82 if (server_connection == NULL) { |
| 84 LOG(ERROR) << "SpdySM: Could not create server connection"; | 83 LOG(ERROR) << "SpdySM: Could not create server connection"; |
| 85 return NULL; | 84 return NULL; |
| 86 } | 85 } |
| 87 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Creating new HTTP interface"; | 86 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Creating new HTTP interface"; |
| 88 SMInterface *sm_http_interface = new HttpSM(server_connection, | 87 SMInterface* sm_http_interface = |
| 89 this, | 88 new HttpSM(server_connection, this, memory_cache_, acceptor_); |
| 90 memory_cache_, | |
| 91 acceptor_); | |
| 92 return sm_http_interface; | 89 return sm_http_interface; |
| 93 } | 90 } |
| 94 | 91 |
| 95 SMInterface* SpdySM::FindOrMakeNewSMConnectionInterface( | 92 SMInterface* SpdySM::FindOrMakeNewSMConnectionInterface( |
| 96 const std::string& server_ip, | 93 const std::string& server_ip, |
| 97 const std::string& server_port) { | 94 const std::string& server_port) { |
| 98 SMInterface *sm_http_interface; | 95 SMInterface* sm_http_interface; |
| 99 int32 server_idx; | 96 int32 server_idx; |
| 100 if (unused_server_interface_list.empty()) { | 97 if (unused_server_interface_list.empty()) { |
| 101 sm_http_interface = NewConnectionInterface(); | 98 sm_http_interface = NewConnectionInterface(); |
| 102 server_idx = server_interface_list.size(); | 99 server_idx = server_interface_list.size(); |
| 103 server_interface_list.push_back(sm_http_interface); | 100 server_interface_list.push_back(sm_http_interface); |
| 104 VLOG(2) << ACCEPTOR_CLIENT_IDENT | 101 VLOG(2) << ACCEPTOR_CLIENT_IDENT |
| 105 << "SpdySM: Making new server connection on index: " | 102 << "SpdySM: Making new server connection on index: " << server_idx; |
| 106 << server_idx; | |
| 107 } else { | 103 } else { |
| 108 server_idx = unused_server_interface_list.back(); | 104 server_idx = unused_server_interface_list.back(); |
| 109 unused_server_interface_list.pop_back(); | 105 unused_server_interface_list.pop_back(); |
| 110 sm_http_interface = server_interface_list.at(server_idx); | 106 sm_http_interface = server_interface_list.at(server_idx); |
| 111 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Reusing connection on " | 107 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Reusing connection on " |
| 112 << "index: " << server_idx; | 108 << "index: " << server_idx; |
| 113 } | 109 } |
| 114 | 110 |
| 115 sm_http_interface->InitSMInterface(this, server_idx); | 111 sm_http_interface->InitSMInterface(this, server_idx); |
| 116 sm_http_interface->InitSMConnection(NULL, | 112 sm_http_interface->InitSMConnection(NULL, |
| 117 sm_http_interface, | 113 sm_http_interface, |
| 118 epoll_server_, | 114 epoll_server_, |
| 119 -1, | 115 -1, |
| 120 server_ip, | 116 server_ip, |
| 121 server_port, | 117 server_port, |
| 122 std::string(), | 118 std::string(), |
| 123 false); | 119 false); |
| 124 | 120 |
| 125 return sm_http_interface; | 121 return sm_http_interface; |
| 126 } | 122 } |
| 127 | 123 |
| 128 int SpdySM::SpdyHandleNewStream( | 124 int SpdySM::SpdyHandleNewStream(SpdyStreamId stream_id, |
| 129 SpdyStreamId stream_id, | 125 SpdyPriority priority, |
| 130 SpdyPriority priority, | 126 const SpdyHeaderBlock& headers, |
| 131 const SpdyHeaderBlock& headers, | 127 std::string& http_data, |
| 132 std::string &http_data, | 128 bool* is_https_scheme) { |
| 133 bool* is_https_scheme) { | |
| 134 *is_https_scheme = false; | 129 *is_https_scheme = false; |
| 135 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnSyn(" | 130 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnSyn(" << stream_id << ")"; |
| 136 << stream_id << ")"; | 131 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: # headers: " << headers.size(); |
| 137 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: # headers: " | |
| 138 << headers.size(); | |
| 139 | 132 |
| 140 SpdyHeaderBlock supplement; | 133 SpdyHeaderBlock supplement; |
| 141 SpdyHeaderBlock::const_iterator method = headers.end(); | 134 SpdyHeaderBlock::const_iterator method = headers.end(); |
| 142 SpdyHeaderBlock::const_iterator host = headers.end(); | 135 SpdyHeaderBlock::const_iterator host = headers.end(); |
| 143 SpdyHeaderBlock::const_iterator path = headers.end(); | 136 SpdyHeaderBlock::const_iterator path = headers.end(); |
| 144 SpdyHeaderBlock::const_iterator scheme = headers.end(); | 137 SpdyHeaderBlock::const_iterator scheme = headers.end(); |
| 145 SpdyHeaderBlock::const_iterator version = headers.end(); | 138 SpdyHeaderBlock::const_iterator version = headers.end(); |
| 146 SpdyHeaderBlock::const_iterator url = headers.end(); | 139 SpdyHeaderBlock::const_iterator url = headers.end(); |
| 147 | 140 |
| 148 if (spdy_version() == SPDY2) { | 141 if (spdy_version() == SPDY2) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 240 |
| 248 void SpdySM::OnSynStream(SpdyStreamId stream_id, | 241 void SpdySM::OnSynStream(SpdyStreamId stream_id, |
| 249 SpdyStreamId associated_stream_id, | 242 SpdyStreamId associated_stream_id, |
| 250 SpdyPriority priority, | 243 SpdyPriority priority, |
| 251 uint8 credential_slot, | 244 uint8 credential_slot, |
| 252 bool fin, | 245 bool fin, |
| 253 bool unidirectional, | 246 bool unidirectional, |
| 254 const SpdyHeaderBlock& headers) { | 247 const SpdyHeaderBlock& headers) { |
| 255 std::string http_data; | 248 std::string http_data; |
| 256 bool is_https_scheme; | 249 bool is_https_scheme; |
| 257 int ret = SpdyHandleNewStream(stream_id, priority, headers, http_data, | 250 int ret = SpdyHandleNewStream( |
| 258 &is_https_scheme); | 251 stream_id, priority, headers, http_data, &is_https_scheme); |
| 259 if (!ret) { | 252 if (!ret) { |
| 260 LOG(ERROR) << "SpdySM: Could not convert spdy into http."; | 253 LOG(ERROR) << "SpdySM: Could not convert spdy into http."; |
| 261 return; | 254 return; |
| 262 } | 255 } |
| 263 // We've seen a valid looking SYN_STREAM, consider this to have | 256 // We've seen a valid looking SYN_STREAM, consider this to have |
| 264 // been a real spdy session. | 257 // been a real spdy session. |
| 265 valid_spdy_session_ = true; | 258 valid_spdy_session_ = true; |
| 266 | 259 |
| 267 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_PROXY) { | 260 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_PROXY) { |
| 268 std::string server_ip; | 261 std::string server_ip; |
| 269 std::string server_port; | 262 std::string server_port; |
| 270 if (is_https_scheme) { | 263 if (is_https_scheme) { |
| 271 server_ip = acceptor_->https_server_ip_; | 264 server_ip = acceptor_->https_server_ip_; |
| 272 server_port = acceptor_->https_server_port_; | 265 server_port = acceptor_->https_server_port_; |
| 273 } else { | 266 } else { |
| 274 server_ip = acceptor_->http_server_ip_; | 267 server_ip = acceptor_->http_server_ip_; |
| 275 server_port = acceptor_->http_server_port_; | 268 server_port = acceptor_->http_server_port_; |
| 276 } | 269 } |
| 277 SMInterface* sm_http_interface = | 270 SMInterface* sm_http_interface = |
| 278 FindOrMakeNewSMConnectionInterface(server_ip, server_port); | 271 FindOrMakeNewSMConnectionInterface(server_ip, server_port); |
| 279 stream_to_smif_[stream_id] = sm_http_interface; | 272 stream_to_smif_[stream_id] = sm_http_interface; |
| 280 sm_http_interface->SetStreamID(stream_id); | 273 sm_http_interface->SetStreamID(stream_id); |
| 281 sm_http_interface->ProcessWriteInput(http_data.c_str(), | 274 sm_http_interface->ProcessWriteInput(http_data.c_str(), http_data.size()); |
| 282 http_data.size()); | |
| 283 } | 275 } |
| 284 } | 276 } |
| 285 | 277 |
| 286 void SpdySM::OnSynReply(SpdyStreamId stream_id, | 278 void SpdySM::OnSynReply(SpdyStreamId stream_id, |
| 287 bool fin, | 279 bool fin, |
| 288 const SpdyHeaderBlock& headers) { | 280 const SpdyHeaderBlock& headers) { |
| 289 // TODO(willchan): if there is an error parsing headers, we | 281 // TODO(willchan): if there is an error parsing headers, we |
| 290 // should send a RST_STREAM. | 282 // should send a RST_STREAM. |
| 291 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnSynReply(" | 283 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnSynReply(" << stream_id << ")"; |
| 292 << stream_id << ")"; | |
| 293 } | 284 } |
| 294 | 285 |
| 295 void SpdySM::OnHeaders(SpdyStreamId stream_id, | 286 void SpdySM::OnHeaders(SpdyStreamId stream_id, |
| 296 bool fin, | 287 bool fin, |
| 297 const SpdyHeaderBlock& headers) { | 288 const SpdyHeaderBlock& headers) { |
| 298 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnHeaders(" | 289 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnHeaders(" << stream_id << ")"; |
| 299 << stream_id << ")"; | |
| 300 } | 290 } |
| 301 | 291 |
| 302 void SpdySM::OnRstStream(SpdyStreamId stream_id, | 292 void SpdySM::OnRstStream(SpdyStreamId stream_id, SpdyRstStreamStatus status) { |
| 303 SpdyRstStreamStatus status) { | 293 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnRstStream(" << stream_id |
| 304 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnRstStream(" | 294 << ")"; |
| 305 << stream_id << ")"; | |
| 306 client_output_ordering_.RemoveStreamId(stream_id); | 295 client_output_ordering_.RemoveStreamId(stream_id); |
| 307 } | 296 } |
| 308 | 297 |
| 309 size_t SpdySM::ProcessReadInput(const char* data, size_t len) { | 298 size_t SpdySM::ProcessReadInput(const char* data, size_t len) { |
| 310 return buffered_spdy_framer_->ProcessInput(data, len); | 299 return buffered_spdy_framer_->ProcessInput(data, len); |
| 311 } | 300 } |
| 312 | 301 |
| 313 size_t SpdySM::ProcessWriteInput(const char* data, size_t len) { | 302 size_t SpdySM::ProcessWriteInput(const char* data, size_t len) { return 0; } |
| 314 return 0; | |
| 315 } | |
| 316 | 303 |
| 317 bool SpdySM::MessageFullyRead() const { | 304 bool SpdySM::MessageFullyRead() const { |
| 318 return buffered_spdy_framer_->MessageFullyRead(); | 305 return buffered_spdy_framer_->MessageFullyRead(); |
| 319 } | 306 } |
| 320 | 307 |
| 321 bool SpdySM::Error() const { | 308 bool SpdySM::Error() const { |
| 322 return close_on_error_ || buffered_spdy_framer_->HasError(); | 309 return close_on_error_ || buffered_spdy_framer_->HasError(); |
| 323 } | 310 } |
| 324 | 311 |
| 325 const char* SpdySM::ErrorAsString() const { | 312 const char* SpdySM::ErrorAsString() const { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 341 valid_spdy_session_ = false; | 328 valid_spdy_session_ = false; |
| 342 client_output_ordering_.Reset(); | 329 client_output_ordering_.Reset(); |
| 343 next_outgoing_stream_id_ = 2; | 330 next_outgoing_stream_id_ = 2; |
| 344 } | 331 } |
| 345 | 332 |
| 346 // Send a settings frame | 333 // Send a settings frame |
| 347 int SpdySM::PostAcceptHook() { | 334 int SpdySM::PostAcceptHook() { |
| 348 SettingsMap settings; | 335 SettingsMap settings; |
| 349 settings[SETTINGS_MAX_CONCURRENT_STREAMS] = | 336 settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 350 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, 100); | 337 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, 100); |
| 351 SpdyFrame* settings_frame = | 338 SpdyFrame* settings_frame = buffered_spdy_framer_->CreateSettings(settings); |
| 352 buffered_spdy_framer_->CreateSettings(settings); | |
| 353 | 339 |
| 354 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Sending Settings Frame"; | 340 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Sending Settings Frame"; |
| 355 EnqueueDataFrame(new SpdyFrameDataFrame(settings_frame)); | 341 EnqueueDataFrame(new SpdyFrameDataFrame(settings_frame)); |
| 356 return 1; | 342 return 1; |
| 357 } | 343 } |
| 358 | 344 |
| 359 void SpdySM::NewStream(uint32 stream_id, | 345 void SpdySM::NewStream(uint32 stream_id, |
| 360 uint32 priority, | 346 uint32 priority, |
| 361 const std::string& filename) { | 347 const std::string& filename) { |
| 362 MemCacheIter mci; | 348 MemCacheIter mci; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 375 } | 361 } |
| 376 } else { | 362 } else { |
| 377 AddToOutputOrder(mci); | 363 AddToOutputOrder(mci); |
| 378 } | 364 } |
| 379 } | 365 } |
| 380 | 366 |
| 381 void SpdySM::AddToOutputOrder(const MemCacheIter& mci) { | 367 void SpdySM::AddToOutputOrder(const MemCacheIter& mci) { |
| 382 client_output_ordering_.AddToOutputOrder(mci); | 368 client_output_ordering_.AddToOutputOrder(mci); |
| 383 } | 369 } |
| 384 | 370 |
| 385 void SpdySM::SendEOF(uint32 stream_id) { | 371 void SpdySM::SendEOF(uint32 stream_id) { SendEOFImpl(stream_id); } |
| 386 SendEOFImpl(stream_id); | |
| 387 } | |
| 388 | 372 |
| 389 void SpdySM::SendErrorNotFound(uint32 stream_id) { | 373 void SpdySM::SendErrorNotFound(uint32 stream_id) { |
| 390 SendErrorNotFoundImpl(stream_id); | 374 SendErrorNotFoundImpl(stream_id); |
| 391 } | 375 } |
| 392 | 376 |
| 393 size_t SpdySM::SendSynStream(uint32 stream_id, const BalsaHeaders& headers) { | 377 size_t SpdySM::SendSynStream(uint32 stream_id, const BalsaHeaders& headers) { |
| 394 return SendSynStreamImpl(stream_id, headers); | 378 return SendSynStreamImpl(stream_id, headers); |
| 395 } | 379 } |
| 396 | 380 |
| 397 size_t SpdySM::SendSynReply(uint32 stream_id, const BalsaHeaders& headers) { | 381 size_t SpdySM::SendSynReply(uint32 stream_id, const BalsaHeaders& headers) { |
| 398 return SendSynReplyImpl(stream_id, headers); | 382 return SendSynReplyImpl(stream_id, headers); |
| 399 } | 383 } |
| 400 | 384 |
| 401 void SpdySM::SendDataFrame(uint32 stream_id, const char* data, int64 len, | 385 void SpdySM::SendDataFrame(uint32 stream_id, |
| 402 uint32 flags, bool compress) { | 386 const char* data, |
| 387 int64 len, |
| 388 uint32 flags, |
| 389 bool compress) { |
| 403 SpdyDataFlags spdy_flags = static_cast<SpdyDataFlags>(flags); | 390 SpdyDataFlags spdy_flags = static_cast<SpdyDataFlags>(flags); |
| 404 SendDataFrameImpl(stream_id, data, len, spdy_flags, compress); | 391 SendDataFrameImpl(stream_id, data, len, spdy_flags, compress); |
| 405 } | 392 } |
| 406 | 393 |
| 407 void SpdySM::SendEOFImpl(uint32 stream_id) { | 394 void SpdySM::SendEOFImpl(uint32 stream_id) { |
| 408 SendDataFrame(stream_id, NULL, 0, DATA_FLAG_FIN, false); | 395 SendDataFrame(stream_id, NULL, 0, DATA_FLAG_FIN, false); |
| 409 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Sending EOF: " << stream_id; | 396 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Sending EOF: " << stream_id; |
| 410 KillStream(stream_id); | 397 KillStream(stream_id); |
| 411 stream_to_smif_.erase(stream_id); | 398 stream_to_smif_.erase(stream_id); |
| 412 } | 399 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 433 if (!hi->first.length() || !hi->second.length()) | 420 if (!hi->first.length() || !hi->second.length()) |
| 434 continue; | 421 continue; |
| 435 | 422 |
| 436 // Key must be all lower case in SPDY headers. | 423 // Key must be all lower case in SPDY headers. |
| 437 std::string key = hi->first.as_string(); | 424 std::string key = hi->first.as_string(); |
| 438 std::transform(key.begin(), key.end(), key.begin(), ::tolower); | 425 std::transform(key.begin(), key.end(), key.begin(), ::tolower); |
| 439 SpdyHeaderBlock::iterator fhi = dest.find(key); | 426 SpdyHeaderBlock::iterator fhi = dest.find(key); |
| 440 if (fhi == dest.end()) { | 427 if (fhi == dest.end()) { |
| 441 dest[key] = hi->second.as_string(); | 428 dest[key] = hi->second.as_string(); |
| 442 } else { | 429 } else { |
| 443 dest[key] = ( | 430 dest[key] = (std::string(fhi->second.data(), fhi->second.size()) + "\0" + |
| 444 std::string(fhi->second.data(), fhi->second.size()) + "\0" + | 431 std::string(hi->second.data(), hi->second.size())); |
| 445 std::string(hi->second.data(), hi->second.size())); | |
| 446 } | 432 } |
| 447 } | 433 } |
| 448 | 434 |
| 449 // These headers have no value | 435 // These headers have no value |
| 450 dest.erase("X-Associated-Content"); // TODO(mbelshe): case-sensitive | 436 dest.erase("X-Associated-Content"); // TODO(mbelshe): case-sensitive |
| 451 dest.erase("X-Original-Url"); // TODO(mbelshe): case-sensitive | 437 dest.erase("X-Original-Url"); // TODO(mbelshe): case-sensitive |
| 452 } | 438 } |
| 453 | 439 |
| 454 size_t SpdySM::SendSynStreamImpl(uint32 stream_id, | 440 size_t SpdySM::SendSynStreamImpl(uint32 stream_id, |
| 455 const BalsaHeaders& headers) { | 441 const BalsaHeaders& headers) { |
| 456 SpdyHeaderBlock block; | 442 SpdyHeaderBlock block; |
| 457 CopyHeaders(block, headers); | 443 CopyHeaders(block, headers); |
| 458 if (spdy_version() == SPDY2) { | 444 if (spdy_version() == SPDY2) { |
| 459 block["method"] = headers.request_method().as_string(); | 445 block["method"] = headers.request_method().as_string(); |
| 460 if (!headers.HasHeader("version")) | 446 if (!headers.HasHeader("version")) |
| 461 block["version"] = headers.request_version().as_string(); | 447 block["version"] = headers.request_version().as_string(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 SpdyFrame* fsrcf = buffered_spdy_framer_->CreateSynReply( | 495 SpdyFrame* fsrcf = buffered_spdy_framer_->CreateSynReply( |
| 510 stream_id, CONTROL_FLAG_NONE, &block); | 496 stream_id, CONTROL_FLAG_NONE, &block); |
| 511 size_t df_size = fsrcf->size(); | 497 size_t df_size = fsrcf->size(); |
| 512 EnqueueDataFrame(new SpdyFrameDataFrame(fsrcf)); | 498 EnqueueDataFrame(new SpdyFrameDataFrame(fsrcf)); |
| 513 | 499 |
| 514 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Sending SynReplyheader " | 500 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Sending SynReplyheader " |
| 515 << stream_id; | 501 << stream_id; |
| 516 return df_size; | 502 return df_size; |
| 517 } | 503 } |
| 518 | 504 |
| 519 void SpdySM::SendDataFrameImpl(uint32 stream_id, const char* data, int64 len, | 505 void SpdySM::SendDataFrameImpl(uint32 stream_id, |
| 520 SpdyDataFlags flags, bool compress) { | 506 const char* data, |
| 507 int64 len, |
| 508 SpdyDataFlags flags, |
| 509 bool compress) { |
| 521 // TODO(mbelshe): We can't compress here - before going into the | 510 // TODO(mbelshe): We can't compress here - before going into the |
| 522 // priority queue. Compression needs to be done | 511 // priority queue. Compression needs to be done |
| 523 // with late binding. | 512 // with late binding. |
| 524 if (len == 0) { | 513 if (len == 0) { |
| 525 SpdyFrame* fdf = buffered_spdy_framer_->CreateDataFrame( | 514 SpdyFrame* fdf = |
| 526 stream_id, data, len, flags); | 515 buffered_spdy_framer_->CreateDataFrame(stream_id, data, len, flags); |
| 527 EnqueueDataFrame(new SpdyFrameDataFrame(fdf)); | 516 EnqueueDataFrame(new SpdyFrameDataFrame(fdf)); |
| 528 return; | 517 return; |
| 529 } | 518 } |
| 530 | 519 |
| 531 // Chop data frames into chunks so that one stream can't monopolize the | 520 // Chop data frames into chunks so that one stream can't monopolize the |
| 532 // output channel. | 521 // output channel. |
| 533 while (len > 0) { | 522 while (len > 0) { |
| 534 int64 size = std::min(len, static_cast<int64>(kSpdySegmentSize)); | 523 int64 size = std::min(len, static_cast<int64>(kSpdySegmentSize)); |
| 535 SpdyDataFlags chunk_flags = flags; | 524 SpdyDataFlags chunk_flags = flags; |
| 536 | 525 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 mci->transformed_header = true; | 557 mci->transformed_header = true; |
| 569 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: GetOutput transformed " | 558 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: GetOutput transformed " |
| 570 << "header stream_id: [" << mci->stream_id << "]"; | 559 << "header stream_id: [" << mci->stream_id << "]"; |
| 571 if ((mci->stream_id % 2) == 0) { | 560 if ((mci->stream_id % 2) == 0) { |
| 572 // this is a server initiated stream. | 561 // this is a server initiated stream. |
| 573 // Ideally, we'd do a 'syn-push' here, instead of a syn-reply. | 562 // Ideally, we'd do a 'syn-push' here, instead of a syn-reply. |
| 574 BalsaHeaders headers; | 563 BalsaHeaders headers; |
| 575 headers.CopyFrom(*(mci->file_data->headers())); | 564 headers.CopyFrom(*(mci->file_data->headers())); |
| 576 headers.ReplaceOrAppendHeader("status", "200"); | 565 headers.ReplaceOrAppendHeader("status", "200"); |
| 577 headers.ReplaceOrAppendHeader("version", "http/1.1"); | 566 headers.ReplaceOrAppendHeader("version", "http/1.1"); |
| 578 headers.SetRequestFirstlineFromStringPieces("PUSH", | 567 headers.SetRequestFirstlineFromStringPieces( |
| 579 mci->file_data->filename(), | 568 "PUSH", mci->file_data->filename(), ""); |
| 580 ""); | |
| 581 mci->bytes_sent = SendSynStream(mci->stream_id, headers); | 569 mci->bytes_sent = SendSynStream(mci->stream_id, headers); |
| 582 } else { | 570 } else { |
| 583 BalsaHeaders headers; | 571 BalsaHeaders headers; |
| 584 headers.CopyFrom(*(mci->file_data->headers())); | 572 headers.CopyFrom(*(mci->file_data->headers())); |
| 585 mci->bytes_sent = SendSynReply(mci->stream_id, headers); | 573 mci->bytes_sent = SendSynReply(mci->stream_id, headers); |
| 586 } | 574 } |
| 587 return; | 575 return; |
| 588 } | 576 } |
| 589 if (mci->body_bytes_consumed >= mci->file_data->body().size()) { | 577 if (mci->body_bytes_consumed >= mci->file_data->body().size()) { |
| 590 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: GetOutput " | 578 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: GetOutput " |
| (...skipping 11 matching lines...) Expand all Loading... |
| 602 if (mci->file_data->headers()->HasHeader("content-type")) { | 590 if (mci->file_data->headers()->HasHeader("content-type")) { |
| 603 std::string content_type = | 591 std::string content_type = |
| 604 mci->file_data->headers()->GetHeader("content-type").as_string(); | 592 mci->file_data->headers()->GetHeader("content-type").as_string(); |
| 605 if (content_type.find("image") == content_type.npos) | 593 if (content_type.find("image") == content_type.npos) |
| 606 should_compress = true; | 594 should_compress = true; |
| 607 } | 595 } |
| 608 } | 596 } |
| 609 | 597 |
| 610 SendDataFrame(mci->stream_id, | 598 SendDataFrame(mci->stream_id, |
| 611 mci->file_data->body().data() + mci->body_bytes_consumed, | 599 mci->file_data->body().data() + mci->body_bytes_consumed, |
| 612 num_to_write, 0, should_compress); | 600 num_to_write, |
| 601 0, |
| 602 should_compress); |
| 613 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: GetOutput SendDataFrame[" | 603 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: GetOutput SendDataFrame[" |
| 614 << mci->stream_id << "]: " << num_to_write; | 604 << mci->stream_id << "]: " << num_to_write; |
| 615 mci->body_bytes_consumed += num_to_write; | 605 mci->body_bytes_consumed += num_to_write; |
| 616 mci->bytes_sent += num_to_write; | 606 mci->bytes_sent += num_to_write; |
| 617 } | 607 } |
| 618 } | 608 } |
| 619 | 609 |
| 620 } // namespace net | 610 } // namespace net |
| OLD | NEW |