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 <string> | 7 #include <string> |
8 | 8 |
9 #include "net/spdy/spdy_framer.h" | 9 #include "net/spdy/spdy_framer.h" |
10 #include "net/spdy/spdy_protocol.h" | 10 #include "net/spdy/spdy_protocol.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 sm_http_interface->InitSMConnection(NULL, sm_http_interface, | 114 sm_http_interface->InitSMConnection(NULL, sm_http_interface, |
115 epoll_server_, -1, | 115 epoll_server_, -1, |
116 server_ip, server_port, "", false); | 116 server_ip, server_port, "", false); |
117 | 117 |
118 return sm_http_interface; | 118 return sm_http_interface; |
119 } | 119 } |
120 | 120 |
121 int SpdySM::SpdyHandleNewStream( | 121 int SpdySM::SpdyHandleNewStream( |
122 SpdyStreamId stream_id, | 122 SpdyStreamId stream_id, |
123 SpdyPriority priority, | 123 SpdyPriority priority, |
124 const linked_ptr<SpdyHeaderBlock>& headers, | 124 const SpdyHeaderBlock& headers, |
125 std::string &http_data, | 125 std::string &http_data, |
126 bool* is_https_scheme) { | 126 bool* is_https_scheme) { |
127 *is_https_scheme = false; | 127 *is_https_scheme = false; |
128 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnSyn(" | 128 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnSyn(" |
129 << stream_id << ")"; | 129 << stream_id << ")"; |
130 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: # headers: " | 130 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: # headers: " |
131 << headers->size(); | 131 << headers.size(); |
132 | 132 |
133 SpdyHeaderBlock::iterator url = headers->find("url"); | 133 SpdyHeaderBlock::const_iterator url = headers.find("url"); |
134 SpdyHeaderBlock::iterator method = headers->find("method"); | 134 SpdyHeaderBlock::const_iterator method = headers.find("method"); |
135 if (url == headers->end() || method == headers->end()) { | 135 if (url == headers.end() || method == headers.end()) { |
136 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: didn't find method or url " | 136 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: didn't find method or url " |
137 << "or method. Not creating stream"; | 137 << "or method. Not creating stream"; |
138 return 0; | 138 return 0; |
139 } | 139 } |
140 | 140 |
141 SpdyHeaderBlock::iterator scheme = headers->find("scheme"); | 141 SpdyHeaderBlock::const_iterator scheme = headers.find("scheme"); |
142 if (scheme->second.compare("https") == 0) { | 142 if (scheme->second.compare("https") == 0) { |
143 *is_https_scheme = true; | 143 *is_https_scheme = true; |
144 } | 144 } |
145 | 145 |
146 // url->second here only ever seems to contain just the path. When this | 146 // url->second here only ever seems to contain just the path. When this |
147 // path contains a query string with a http:// in one of its values, | 147 // path contains a query string with a http:// in one of its values, |
148 // UrlUtilities::GetUrlPath will fail and always return a / breaking | 148 // UrlUtilities::GetUrlPath will fail and always return a / breaking |
149 // the request. GetUrlPath assumes the absolute URL is being passed in. | 149 // the request. GetUrlPath assumes the absolute URL is being passed in. |
150 std::string uri; | 150 std::string uri; |
151 if (url->second.compare(0,4,"http") == 0) | 151 if (url->second.compare(0,4,"http") == 0) |
152 uri = UrlUtilities::GetUrlPath(url->second); | 152 uri = UrlUtilities::GetUrlPath(url->second); |
153 else | 153 else |
154 uri = std::string(url->second); | 154 uri = std::string(url->second); |
155 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_SPDY_SERVER) { | 155 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_SPDY_SERVER) { |
156 std::string host = UrlUtilities::GetUrlHost(url->second); | 156 std::string host = UrlUtilities::GetUrlHost(url->second); |
157 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Request: " << method->second | 157 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Request: " << method->second |
158 << " " << uri; | 158 << " " << uri; |
159 std::string filename = EncodeURL(uri, host, method->second); | 159 std::string filename = EncodeURL(uri, host, method->second); |
160 NewStream(stream_id, priority, filename); | 160 NewStream(stream_id, priority, filename); |
161 } else { | 161 } else { |
162 SpdyHeaderBlock::iterator version = headers->find("version"); | 162 SpdyHeaderBlock::const_iterator version = headers.find("version"); |
163 http_data += method->second + " " + uri + " " + version->second + "\r\n"; | 163 http_data += method->second + " " + uri + " " + version->second + "\r\n"; |
164 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Request: " << method->second << " " | 164 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Request: " << method->second << " " |
165 << uri << " " << version->second; | 165 << uri << " " << version->second; |
166 for (SpdyHeaderBlock::iterator i = headers->begin(); | 166 for (SpdyHeaderBlock::const_iterator i = headers.begin(); |
167 i != headers->end(); ++i) { | 167 i != headers.end(); ++i) { |
168 http_data += i->first + ": " + i->second + "\r\n"; | 168 http_data += i->first + ": " + i->second + "\r\n"; |
169 VLOG(2) << ACCEPTOR_CLIENT_IDENT << i->first.c_str() << ":" | 169 VLOG(2) << ACCEPTOR_CLIENT_IDENT << i->first.c_str() << ":" |
170 << i->second.c_str(); | 170 << i->second.c_str(); |
171 } | 171 } |
172 if (forward_ip_header_.length()) { | 172 if (forward_ip_header_.length()) { |
173 // X-Client-Cluster-IP header | 173 // X-Client-Cluster-IP header |
174 http_data += forward_ip_header_ + ": " + | 174 http_data += forward_ip_header_ + ": " + |
175 connection_->client_ip() + "\r\n"; | 175 connection_->client_ip() + "\r\n"; |
176 } | 176 } |
177 http_data += "\r\n"; | 177 http_data += "\r\n"; |
(...skipping 19 matching lines...) Expand all Loading... |
197 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_PROXY) | 197 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_PROXY) |
198 interface->ProcessWriteInput(data, len); | 198 interface->ProcessWriteInput(data, len); |
199 } | 199 } |
200 | 200 |
201 void SpdySM::OnSynStream(SpdyStreamId stream_id, | 201 void SpdySM::OnSynStream(SpdyStreamId stream_id, |
202 SpdyStreamId associated_stream_id, | 202 SpdyStreamId associated_stream_id, |
203 SpdyPriority priority, | 203 SpdyPriority priority, |
204 uint8 credential_slot, | 204 uint8 credential_slot, |
205 bool fin, | 205 bool fin, |
206 bool unidirectional, | 206 bool unidirectional, |
207 const linked_ptr<SpdyHeaderBlock>& headers) { | 207 const SpdyHeaderBlock& headers) { |
208 std::string http_data; | 208 std::string http_data; |
209 bool is_https_scheme; | 209 bool is_https_scheme; |
210 int ret = SpdyHandleNewStream(stream_id, priority, headers, http_data, | 210 int ret = SpdyHandleNewStream(stream_id, priority, headers, http_data, |
211 &is_https_scheme); | 211 &is_https_scheme); |
212 if (!ret) { | 212 if (!ret) { |
213 LOG(ERROR) << "SpdySM: Could not convert spdy into http."; | 213 LOG(ERROR) << "SpdySM: Could not convert spdy into http."; |
214 return; | 214 return; |
215 } | 215 } |
216 // We've seen a valid looking SYN_STREAM, consider this to have | 216 // We've seen a valid looking SYN_STREAM, consider this to have |
217 // been a real spdy session. | 217 // been a real spdy session. |
(...skipping 13 matching lines...) Expand all Loading... |
231 FindOrMakeNewSMConnectionInterface(server_ip, server_port); | 231 FindOrMakeNewSMConnectionInterface(server_ip, server_port); |
232 stream_to_smif_[stream_id] = sm_http_interface; | 232 stream_to_smif_[stream_id] = sm_http_interface; |
233 sm_http_interface->SetStreamID(stream_id); | 233 sm_http_interface->SetStreamID(stream_id); |
234 sm_http_interface->ProcessWriteInput(http_data.c_str(), | 234 sm_http_interface->ProcessWriteInput(http_data.c_str(), |
235 http_data.size()); | 235 http_data.size()); |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 void SpdySM::OnSynReply(SpdyStreamId stream_id, | 239 void SpdySM::OnSynReply(SpdyStreamId stream_id, |
240 bool fin, | 240 bool fin, |
241 const linked_ptr<SpdyHeaderBlock>& headers) { | 241 const SpdyHeaderBlock& headers) { |
242 // TODO(willchan): if there is an error parsing headers, we | 242 // TODO(willchan): if there is an error parsing headers, we |
243 // should send a RST_STREAM. | 243 // should send a RST_STREAM. |
244 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnSynReply(" | 244 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnSynReply(" |
245 << stream_id << ")"; | 245 << stream_id << ")"; |
246 } | 246 } |
247 | 247 |
248 void SpdySM::OnHeaders(SpdyStreamId stream_id, | 248 void SpdySM::OnHeaders(SpdyStreamId stream_id, |
249 bool fin, | 249 bool fin, |
250 const linked_ptr<SpdyHeaderBlock>& headers) { | 250 const SpdyHeaderBlock& headers) { |
251 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnHeaders(" | 251 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnHeaders(" |
252 << stream_id << ")"; | 252 << stream_id << ")"; |
253 } | 253 } |
254 | 254 |
255 void SpdySM::OnRstStream(SpdyStreamId stream_id, | 255 void SpdySM::OnRstStream(SpdyStreamId stream_id, |
256 SpdyStatusCodes status) { | 256 SpdyStatusCodes status) { |
257 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnRstStream(" | 257 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: OnRstStream(" |
258 << stream_id << ")"; | 258 << stream_id << ")"; |
259 client_output_ordering_.RemoveStreamId(stream_id); | 259 client_output_ordering_.RemoveStreamId(stream_id); |
260 } | 260 } |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 mci->file_data->body.data() + mci->body_bytes_consumed, | 549 mci->file_data->body.data() + mci->body_bytes_consumed, |
550 num_to_write, 0, should_compress); | 550 num_to_write, 0, should_compress); |
551 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: GetOutput SendDataFrame[" | 551 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: GetOutput SendDataFrame[" |
552 << mci->stream_id << "]: " << num_to_write; | 552 << mci->stream_id << "]: " << num_to_write; |
553 mci->body_bytes_consumed += num_to_write; | 553 mci->body_bytes_consumed += num_to_write; |
554 mci->bytes_sent += num_to_write; | 554 mci->bytes_sent += num_to_write; |
555 } | 555 } |
556 } | 556 } |
557 | 557 |
558 } // namespace net | 558 } // namespace net |
OLD | NEW |