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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 client_output_list_(connection->output_list()), | 44 client_output_list_(connection->output_list()), |
45 client_output_ordering_(connection), | 45 client_output_ordering_(connection), |
46 next_outgoing_stream_id_(2), | 46 next_outgoing_stream_id_(2), |
47 epoll_server_(epoll_server), | 47 epoll_server_(epoll_server), |
48 acceptor_(acceptor), | 48 acceptor_(acceptor), |
49 memory_cache_(memory_cache), | 49 memory_cache_(memory_cache), |
50 close_on_error_(false) { | 50 close_on_error_(false) { |
51 buffered_spdy_framer_->set_visitor(this); | 51 buffered_spdy_framer_->set_visitor(this); |
52 } | 52 } |
53 | 53 |
54 SpdySM::~SpdySM() { } | 54 SpdySM::~SpdySM() { |
| 55 } |
55 | 56 |
56 void SpdySM::InitSMConnection(SMConnectionPoolInterface* connection_pool, | 57 void SpdySM::InitSMConnection(SMConnectionPoolInterface* connection_pool, |
57 SMInterface* sm_interface, | 58 SMInterface* sm_interface, |
58 EpollServer* epoll_server, | 59 EpollServer* epoll_server, |
59 int fd, | 60 int fd, |
60 std::string server_ip, | 61 std::string server_ip, |
61 std::string server_port, | 62 std::string server_port, |
62 std::string remote_ip, | 63 std::string remote_ip, |
63 bool use_ssl) { | 64 bool use_ssl) { |
64 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Initializing server connection."; | 65 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Initializing server connection."; |
65 connection_->InitSMConnection(connection_pool, | 66 connection_->InitSMConnection(connection_pool, |
66 sm_interface, | 67 sm_interface, |
67 epoll_server, | 68 epoll_server, |
68 fd, | 69 fd, |
69 server_ip, | 70 server_ip, |
70 server_port, | 71 server_port, |
71 remote_ip, | 72 remote_ip, |
72 use_ssl); | 73 use_ssl); |
73 } | 74 } |
74 | 75 |
75 SMInterface* SpdySM::NewConnectionInterface() { | 76 SMInterface* SpdySM::NewConnectionInterface() { |
76 SMConnection* server_connection = | 77 SMConnection* server_connection = SMConnection::NewSMConnection( |
77 SMConnection::NewSMConnection(epoll_server_, | 78 epoll_server_, NULL, memory_cache_, acceptor_, "http_conn: "); |
78 NULL, | |
79 memory_cache_, | |
80 acceptor_, | |
81 "http_conn: "); | |
82 if (server_connection == NULL) { | 79 if (server_connection == NULL) { |
83 LOG(ERROR) << "SpdySM: Could not create server connection"; | 80 LOG(ERROR) << "SpdySM: Could not create server connection"; |
84 return NULL; | 81 return NULL; |
85 } | 82 } |
86 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Creating new HTTP interface"; | 83 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Creating new HTTP interface"; |
87 SMInterface* sm_http_interface = | 84 SMInterface* sm_http_interface = |
88 new HttpSM(server_connection, this, memory_cache_, acceptor_); | 85 new HttpSM(server_connection, this, memory_cache_, acceptor_); |
89 return sm_http_interface; | 86 return sm_http_interface; |
90 } | 87 } |
91 | 88 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 host_string = host->second; | 168 host_string = host->second; |
172 path_string = path->second; | 169 path_string = path->second; |
173 version_string = "HTTP/1.1"; | 170 version_string = "HTTP/1.1"; |
174 } | 171 } |
175 | 172 |
176 if (scheme->second.compare("https") == 0) { | 173 if (scheme->second.compare("https") == 0) { |
177 *is_https_scheme = true; | 174 *is_https_scheme = true; |
178 } | 175 } |
179 | 176 |
180 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_SPDY_SERVER) { | 177 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_SPDY_SERVER) { |
181 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Request: " << method->second | 178 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Request: " << method->second << " " |
182 << " " << path_string; | 179 << path_string; |
183 std::string filename = EncodeURL(path_string, | 180 std::string filename = EncodeURL(path_string, host_string, method->second); |
184 host_string, | |
185 method->second); | |
186 NewStream(stream_id, priority, filename); | 181 NewStream(stream_id, priority, filename); |
187 } else { | 182 } else { |
188 http_data += | 183 http_data += |
189 method->second + " " + path_string + " " + version_string + "\r\n"; | 184 method->second + " " + path_string + " " + version_string + "\r\n"; |
190 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Request: " << method->second << " " | 185 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Request: " << method->second << " " |
191 << path_string << " " << version_string; | 186 << path_string << " " << version_string; |
192 http_data += "Host: " + (*is_https_scheme ? | 187 http_data += "Host: " + (*is_https_scheme ? acceptor_->https_server_ip_ |
193 acceptor_->https_server_ip_ : | 188 : acceptor_->http_server_ip_) + |
194 acceptor_->http_server_ip_) + "\r\n"; | 189 "\r\n"; |
195 for (SpdyHeaderBlock::const_iterator i = headers.begin(); | 190 for (SpdyHeaderBlock::const_iterator i = headers.begin(); |
196 i != headers.end(); ++i) { | 191 i != headers.end(); |
197 if ((i->first.size() > 0 && i->first[0] == ':') || | 192 ++i) { |
198 i->first == "host" || | 193 if ((i->first.size() > 0 && i->first[0] == ':') || i->first == "host" || |
199 i == method || | 194 i == method || i == host || i == path || i == scheme || |
200 i == host || | 195 i == version || i == url) { |
201 i == path || | |
202 i == scheme || | |
203 i == version || | |
204 i == url) { | |
205 // Ignore the entry. | 196 // Ignore the entry. |
206 } else { | 197 } else { |
207 http_data += i->first + ": " + i->second + "\r\n"; | 198 http_data += i->first + ": " + i->second + "\r\n"; |
208 VLOG(2) << ACCEPTOR_CLIENT_IDENT << i->first.c_str() << ":" | 199 VLOG(2) << ACCEPTOR_CLIENT_IDENT << i->first.c_str() << ":" |
209 << i->second.c_str(); | 200 << i->second.c_str(); |
210 } | 201 } |
211 } | 202 } |
212 if (forward_ip_header_.length()) { | 203 if (forward_ip_header_.length()) { |
213 // X-Client-Cluster-IP header | 204 // X-Client-Cluster-IP header |
214 http_data += forward_ip_header_ + ": " + | 205 http_data += |
215 connection_->client_ip() + "\r\n"; | 206 forward_ip_header_ + ": " + connection_->client_ip() + "\r\n"; |
216 } | 207 } |
217 http_data += "\r\n"; | 208 http_data += "\r\n"; |
218 } | 209 } |
219 | 210 |
220 VLOG(3) << ACCEPTOR_CLIENT_IDENT << "SpdySM: HTTP Request:\n" << http_data; | 211 VLOG(3) << ACCEPTOR_CLIENT_IDENT << "SpdySM: HTTP Request:\n" << http_data; |
221 return 1; | 212 return 1; |
222 } | 213 } |
223 | 214 |
224 void SpdySM::OnStreamFrameData(SpdyStreamId stream_id, | 215 void SpdySM::OnStreamFrameData(SpdyStreamId stream_id, |
225 const char* data, | 216 const char* data, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnRstStream(" << stream_id | 285 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnRstStream(" << stream_id |
295 << ")"; | 286 << ")"; |
296 client_output_ordering_.RemoveStreamId(stream_id); | 287 client_output_ordering_.RemoveStreamId(stream_id); |
297 } | 288 } |
298 | 289 |
299 size_t SpdySM::ProcessReadInput(const char* data, size_t len) { | 290 size_t SpdySM::ProcessReadInput(const char* data, size_t len) { |
300 DCHECK(buffered_spdy_framer_); | 291 DCHECK(buffered_spdy_framer_); |
301 return buffered_spdy_framer_->ProcessInput(data, len); | 292 return buffered_spdy_framer_->ProcessInput(data, len); |
302 } | 293 } |
303 | 294 |
304 size_t SpdySM::ProcessWriteInput(const char* data, size_t len) { return 0; } | 295 size_t SpdySM::ProcessWriteInput(const char* data, size_t len) { |
| 296 return 0; |
| 297 } |
305 | 298 |
306 bool SpdySM::MessageFullyRead() const { | 299 bool SpdySM::MessageFullyRead() const { |
307 DCHECK(buffered_spdy_framer_); | 300 DCHECK(buffered_spdy_framer_); |
308 return buffered_spdy_framer_->MessageFullyRead(); | 301 return buffered_spdy_framer_->MessageFullyRead(); |
309 } | 302 } |
310 | 303 |
311 bool SpdySM::Error() const { | 304 bool SpdySM::Error() const { |
312 DCHECK(buffered_spdy_framer_); | 305 DCHECK(buffered_spdy_framer_); |
313 return close_on_error_ || buffered_spdy_framer_->HasError(); | 306 return close_on_error_ || buffered_spdy_framer_->HasError(); |
314 } | 307 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 } | 359 } |
367 } else { | 360 } else { |
368 AddToOutputOrder(mci); | 361 AddToOutputOrder(mci); |
369 } | 362 } |
370 } | 363 } |
371 | 364 |
372 void SpdySM::AddToOutputOrder(const MemCacheIter& mci) { | 365 void SpdySM::AddToOutputOrder(const MemCacheIter& mci) { |
373 client_output_ordering_.AddToOutputOrder(mci); | 366 client_output_ordering_.AddToOutputOrder(mci); |
374 } | 367 } |
375 | 368 |
376 void SpdySM::SendEOF(uint32 stream_id) { SendEOFImpl(stream_id); } | 369 void SpdySM::SendEOF(uint32 stream_id) { |
| 370 SendEOFImpl(stream_id); |
| 371 } |
377 | 372 |
378 void SpdySM::SendErrorNotFound(uint32 stream_id) { | 373 void SpdySM::SendErrorNotFound(uint32 stream_id) { |
379 SendErrorNotFoundImpl(stream_id); | 374 SendErrorNotFoundImpl(stream_id); |
380 } | 375 } |
381 | 376 |
382 size_t SpdySM::SendSynStream(uint32 stream_id, const BalsaHeaders& headers) { | 377 size_t SpdySM::SendSynStream(uint32 stream_id, const BalsaHeaders& headers) { |
383 return SendSynStreamImpl(stream_id, headers); | 378 return SendSynStreamImpl(stream_id, headers); |
384 } | 379 } |
385 | 380 |
386 size_t SpdySM::SendSynReply(uint32 stream_id, const BalsaHeaders& headers) { | 381 size_t SpdySM::SendSynReply(uint32 stream_id, const BalsaHeaders& headers) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Sending SynStreamheader " | 478 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Sending SynStreamheader " |
484 << stream_id; | 479 << stream_id; |
485 return df_size; | 480 return df_size; |
486 } | 481 } |
487 | 482 |
488 size_t SpdySM::SendSynReplyImpl(uint32 stream_id, const BalsaHeaders& headers) { | 483 size_t SpdySM::SendSynReplyImpl(uint32 stream_id, const BalsaHeaders& headers) { |
489 SpdyHeaderBlock block; | 484 SpdyHeaderBlock block; |
490 CopyHeaders(block, headers); | 485 CopyHeaders(block, headers); |
491 if (spdy_version() == SPDY2) { | 486 if (spdy_version() == SPDY2) { |
492 block["status"] = headers.response_code().as_string() + " " + | 487 block["status"] = headers.response_code().as_string() + " " + |
493 headers.response_reason_phrase().as_string(); | 488 headers.response_reason_phrase().as_string(); |
494 block["version"] = headers.response_version().as_string(); | 489 block["version"] = headers.response_version().as_string(); |
495 } else { | 490 } else { |
496 block[":status"] = headers.response_code().as_string() + " " + | 491 block[":status"] = headers.response_code().as_string() + " " + |
497 headers.response_reason_phrase().as_string(); | 492 headers.response_reason_phrase().as_string(); |
498 block[":version"] = headers.response_version().as_string(); | 493 block[":version"] = headers.response_version().as_string(); |
499 } | 494 } |
500 | 495 |
501 DCHECK(buffered_spdy_framer_); | 496 DCHECK(buffered_spdy_framer_); |
502 SpdyFrame* fsrcf = buffered_spdy_framer_->CreateSynReply( | 497 SpdyFrame* fsrcf = buffered_spdy_framer_->CreateSynReply( |
503 stream_id, CONTROL_FLAG_NONE, &block); | 498 stream_id, CONTROL_FLAG_NONE, &block); |
504 size_t df_size = fsrcf->size(); | 499 size_t df_size = fsrcf->size(); |
505 EnqueueDataFrame(new SpdyFrameDataFrame(fsrcf)); | 500 EnqueueDataFrame(new SpdyFrameDataFrame(fsrcf)); |
506 | 501 |
507 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Sending SynReplyheader " | 502 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Sending SynReplyheader " |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 } | 610 } |
616 } | 611 } |
617 | 612 |
618 void SpdySM::CreateFramer(SpdyMajorVersion spdy_version) { | 613 void SpdySM::CreateFramer(SpdyMajorVersion spdy_version) { |
619 DCHECK(!buffered_spdy_framer_); | 614 DCHECK(!buffered_spdy_framer_); |
620 buffered_spdy_framer_.reset(new BufferedSpdyFramer(spdy_version, true)); | 615 buffered_spdy_framer_.reset(new BufferedSpdyFramer(spdy_version, true)); |
621 buffered_spdy_framer_->set_visitor(this); | 616 buffered_spdy_framer_->set_visitor(this); |
622 } | 617 } |
623 | 618 |
624 } // namespace net | 619 } // namespace net |
OLD | NEW |