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

Side by Side Diff: net/tools/flip_server/http_interface.cc

Issue 93793004: Format and Refactor Flip Server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years 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
« no previous file with comments | « net/tools/flip_server/http_interface.h ('k') | net/tools/flip_server/http_interface_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/http_interface.h" 5 #include "net/tools/flip_server/http_interface.h"
6 6
7 #include "net/tools/balsa/balsa_frame.h" 7 #include "net/tools/balsa/balsa_frame.h"
8 #include "net/tools/dump_cache/url_utilities.h" 8 #include "net/tools/dump_cache/url_utilities.h"
9 #include "net/tools/flip_server/flip_config.h" 9 #include "net/tools/flip_server/flip_config.h"
10 #include "net/tools/flip_server/sm_connection.h" 10 #include "net/tools/flip_server/sm_connection.h"
(...skipping 28 matching lines...) Expand all
39 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_PROXY) { 39 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_PROXY) {
40 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: Process Body Data: stream " 40 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: Process Body Data: stream "
41 << stream_id_ << ": size " << size; 41 << stream_id_ << ": size " << size;
42 sm_spdy_interface_->SendDataFrame(stream_id_, input, size, 0, false); 42 sm_spdy_interface_->SendDataFrame(stream_id_, input, size, 0, false);
43 } 43 }
44 } 44 }
45 45
46 void HttpSM::ProcessHeaders(const BalsaHeaders& headers) { 46 void HttpSM::ProcessHeaders(const BalsaHeaders& headers) {
47 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_HTTP_SERVER) { 47 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_HTTP_SERVER) {
48 std::string host = 48 std::string host =
49 UrlUtilities::GetUrlHost(headers.GetHeader("Host").as_string()); 49 UrlUtilities::GetUrlHost(headers.GetHeader("Host").as_string());
50 std::string method = headers.request_method().as_string(); 50 std::string method = headers.request_method().as_string();
51 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Received Request: " 51 VLOG(1) << ACCEPTOR_CLIENT_IDENT
52 << headers.request_uri().as_string() << " " << method; 52 << "Received Request: " << headers.request_uri().as_string() << " "
53 std::string filename = EncodeURL(headers.request_uri().as_string(), 53 << method;
54 host, method); 54 std::string filename =
55 EncodeURL(headers.request_uri().as_string(), host, method);
55 NewStream(stream_id_, 0, filename); 56 NewStream(stream_id_, 0, filename);
56 stream_id_ += 2; 57 stream_id_ += 2;
57 } else { 58 } else {
58 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "HttpSM: Received Response from " 59 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "HttpSM: Received Response from "
59 << connection_->server_ip_ << ":" 60 << connection_->server_ip_ << ":" << connection_->server_port_
60 << connection_->server_port_ << " "; 61 << " ";
61 sm_spdy_interface_->SendSynReply(stream_id_, headers); 62 sm_spdy_interface_->SendSynReply(stream_id_, headers);
62 } 63 }
63 } 64 }
64 65
65 void HttpSM::MessageDone() { 66 void HttpSM::MessageDone() {
66 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_PROXY) { 67 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_PROXY) {
67 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: MessageDone. Sending EOF: " 68 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: MessageDone. Sending EOF: "
68 << "stream " << stream_id_; 69 << "stream " << stream_id_;
69 sm_spdy_interface_->SendEOF(stream_id_); 70 sm_spdy_interface_->SendEOF(stream_id_);
70 } else { 71 } else {
71 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: MessageDone."; 72 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: MessageDone.";
72 } 73 }
73 } 74 }
74 75
75 void HttpSM::HandleHeaderError(BalsaFrame* framer) { 76 void HttpSM::HandleHeaderError(BalsaFrame* framer) { HandleError(); }
76 HandleError();
77 }
78 77
79 void HttpSM::HandleChunkingError(BalsaFrame* framer) { 78 void HttpSM::HandleChunkingError(BalsaFrame* framer) { HandleError(); }
80 HandleError();
81 }
82 79
83 void HttpSM::HandleBodyError(BalsaFrame* framer) { 80 void HttpSM::HandleBodyError(BalsaFrame* framer) { HandleError(); }
84 HandleError();
85 }
86 81
87 void HttpSM::HandleError() { 82 void HttpSM::HandleError() {
88 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Error detected"; 83 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Error detected";
89 } 84 }
90 85
91 void HttpSM::AddToOutputOrder(const MemCacheIter& mci) { 86 void HttpSM::AddToOutputOrder(const MemCacheIter& mci) {
92 output_ordering_.AddToOutputOrder(mci); 87 output_ordering_.AddToOutputOrder(mci);
93 } 88 }
94 89
95 void HttpSM::InitSMInterface(SMInterface* sm_spdy_interface, 90 void HttpSM::InitSMInterface(SMInterface* sm_spdy_interface, int32 server_idx) {
96 int32 server_idx) {
97 sm_spdy_interface_ = sm_spdy_interface; 91 sm_spdy_interface_ = sm_spdy_interface;
98 server_idx_ = server_idx; 92 server_idx_ = server_idx;
99 } 93 }
100 94
101 void HttpSM::InitSMConnection(SMConnectionPoolInterface* connection_pool, 95 void HttpSM::InitSMConnection(SMConnectionPoolInterface* connection_pool,
102 SMInterface* sm_interface, 96 SMInterface* sm_interface,
103 EpollServer* epoll_server, 97 EpollServer* epoll_server,
104 int fd, 98 int fd,
105 std::string server_ip, 99 std::string server_ip,
106 std::string server_port, 100 std::string server_port,
(...skipping 27 matching lines...) Expand all
134 data_frame->size = len; 128 data_frame->size = len;
135 data_frame->delete_when_done = true; 129 data_frame->delete_when_done = true;
136 connection_->EnqueueDataFrame(data_frame); 130 connection_->EnqueueDataFrame(data_frame);
137 return len; 131 return len;
138 } 132 }
139 133
140 bool HttpSM::MessageFullyRead() const { 134 bool HttpSM::MessageFullyRead() const {
141 return http_framer_->MessageFullyRead(); 135 return http_framer_->MessageFullyRead();
142 } 136 }
143 137
144 void HttpSM::SetStreamID(uint32 stream_id) { 138 void HttpSM::SetStreamID(uint32 stream_id) { stream_id_ = stream_id; }
145 stream_id_ = stream_id;
146 }
147 139
148 bool HttpSM::Error() const { 140 bool HttpSM::Error() const { return http_framer_->Error(); }
149 return http_framer_->Error();
150 }
151 141
152 const char* HttpSM::ErrorAsString() const { 142 const char* HttpSM::ErrorAsString() const {
153 return BalsaFrameEnums::ErrorCodeToString(http_framer_->ErrorCode()); 143 return BalsaFrameEnums::ErrorCodeToString(http_framer_->ErrorCode());
154 } 144 }
155 145
156 void HttpSM::Reset() { 146 void HttpSM::Reset() {
157 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "HttpSM: Reset: stream " 147 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "HttpSM: Reset: stream " << stream_id_;
158 << stream_id_;
159 http_framer_->Reset(); 148 http_framer_->Reset();
160 } 149 }
161 150
162 void HttpSM::ResetForNewConnection() { 151 void HttpSM::ResetForNewConnection() {
163 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_PROXY) { 152 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_PROXY) {
164 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "HttpSM: Server connection closing " 153 VLOG(1) << ACCEPTOR_CLIENT_IDENT << "HttpSM: Server connection closing "
165 << "to: " << connection_->server_ip_ << ":" 154 << "to: " << connection_->server_ip_ << ":"
166 << connection_->server_port_ << " "; 155 << connection_->server_port_ << " ";
167 } 156 }
168 // Message has not been fully read, either it is incomplete or the 157 // Message has not been fully read, either it is incomplete or the
169 // server is closing the connection to signal message end. 158 // server is closing the connection to signal message end.
170 if (!MessageFullyRead()) { 159 if (!MessageFullyRead()) {
171 VLOG(2) << "HTTP response closed before end of file detected. " 160 VLOG(2) << "HTTP response closed before end of file detected. "
172 << "Sending EOF to spdy."; 161 << "Sending EOF to spdy.";
173 sm_spdy_interface_->SendEOF(stream_id_); 162 sm_spdy_interface_->SendEOF(stream_id_);
174 } 163 }
175 output_ordering_.Reset(); 164 output_ordering_.Reset();
176 http_framer_->Reset(); 165 http_framer_->Reset();
177 if (sm_spdy_interface_) { 166 if (sm_spdy_interface_) {
178 sm_spdy_interface_->ResetForNewInterface(server_idx_); 167 sm_spdy_interface_->ResetForNewInterface(server_idx_);
179 } 168 }
180 } 169 }
181 170
182 void HttpSM::Cleanup() { 171 void HttpSM::Cleanup() {
183 if (!(acceptor_->flip_handler_type_ == FLIP_HANDLER_HTTP_SERVER)) { 172 if (!(acceptor_->flip_handler_type_ == FLIP_HANDLER_HTTP_SERVER)) {
184 VLOG(2) << "HttpSM Request Fully Read; stream_id: " << stream_id_; 173 VLOG(2) << "HttpSM Request Fully Read; stream_id: " << stream_id_;
185 connection_->Cleanup("request complete"); 174 connection_->Cleanup("request complete");
186 } 175 }
187 } 176 }
188 177
189 int HttpSM::PostAcceptHook() { 178 int HttpSM::PostAcceptHook() { return 1; }
190 return 1;
191 }
192 179
193 void HttpSM::NewStream(uint32 stream_id, uint32 priority, 180 void HttpSM::NewStream(uint32 stream_id,
181 uint32 priority,
194 const std::string& filename) { 182 const std::string& filename) {
195 MemCacheIter mci; 183 MemCacheIter mci;
196 mci.stream_id = stream_id; 184 mci.stream_id = stream_id;
197 mci.priority = priority; 185 mci.priority = priority;
198 if (!memory_cache_->AssignFileData(filename, &mci)) { 186 if (!memory_cache_->AssignFileData(filename, &mci)) {
199 // error creating new stream. 187 // error creating new stream.
200 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "Sending ErrorNotFound"; 188 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "Sending ErrorNotFound";
201 SendErrorNotFound(stream_id); 189 SendErrorNotFound(stream_id);
202 } else { 190 } else {
203 AddToOutputOrder(mci); 191 AddToOutputOrder(mci);
(...skipping 12 matching lines...) Expand all
216 } 204 }
217 205
218 size_t HttpSM::SendSynStream(uint32 stream_id, const BalsaHeaders& headers) { 206 size_t HttpSM::SendSynStream(uint32 stream_id, const BalsaHeaders& headers) {
219 return 0; 207 return 0;
220 } 208 }
221 209
222 size_t HttpSM::SendSynReply(uint32 stream_id, const BalsaHeaders& headers) { 210 size_t HttpSM::SendSynReply(uint32 stream_id, const BalsaHeaders& headers) {
223 return SendSynReplyImpl(stream_id, headers); 211 return SendSynReplyImpl(stream_id, headers);
224 } 212 }
225 213
226 void HttpSM::SendDataFrame(uint32 stream_id, const char* data, int64 len, 214 void HttpSM::SendDataFrame(uint32 stream_id,
227 uint32 flags, bool compress) { 215 const char* data,
216 int64 len,
217 uint32 flags,
218 bool compress) {
228 SendDataFrameImpl(stream_id, data, len, flags, compress); 219 SendDataFrameImpl(stream_id, data, len, flags, compress);
229 } 220 }
230 221
231 void HttpSM::SendEOFImpl(uint32 stream_id) { 222 void HttpSM::SendEOFImpl(uint32 stream_id) {
232 DataFrame* df = new DataFrame; 223 DataFrame* df = new DataFrame;
233 df->data = "0\r\n\r\n"; 224 df->data = "0\r\n\r\n";
234 df->size = 5; 225 df->size = 5;
235 df->delete_when_done = false; 226 df->delete_when_done = false;
236 EnqueueDataFrame(df); 227 EnqueueDataFrame(df);
237 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_HTTP_SERVER) { 228 if (acceptor_->flip_handler_type_ == FLIP_HANDLER_HTTP_SERVER) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 df->data = buffer; 267 df->data = buffer;
277 df->delete_when_done = true; 268 df->delete_when_done = true;
278 sb.Read(buffer, df->size); 269 sb.Read(buffer, df->size);
279 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "Sending HTTP Reply header " 270 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "Sending HTTP Reply header "
280 << stream_id_; 271 << stream_id_;
281 size_t df_size = df->size; 272 size_t df_size = df->size;
282 EnqueueDataFrame(df); 273 EnqueueDataFrame(df);
283 return df_size; 274 return df_size;
284 } 275 }
285 276
286 void HttpSM::SendDataFrameImpl(uint32 stream_id, const char* data, int64 len, 277 void HttpSM::SendDataFrameImpl(uint32 stream_id,
287 uint32 flags, bool compress) { 278 const char* data,
279 int64 len,
280 uint32 flags,
281 bool compress) {
288 char chunk_buf[128]; 282 char chunk_buf[128];
289 snprintf(chunk_buf, sizeof(chunk_buf), "%x\r\n", (unsigned int)len); 283 snprintf(chunk_buf, sizeof(chunk_buf), "%x\r\n", (unsigned int)len);
290 std::string chunk_description(chunk_buf); 284 std::string chunk_description(chunk_buf);
291 DataFrame* df = new DataFrame; 285 DataFrame* df = new DataFrame;
292 df->size = chunk_description.size() + len + 2; 286 df->size = chunk_description.size() + len + 2;
293 char* buffer = new char[df->size]; 287 char* buffer = new char[df->size];
294 df->data = buffer; 288 df->data = buffer;
295 df->delete_when_done = true; 289 df->delete_when_done = true;
296 memcpy(buffer, chunk_description.data(), chunk_description.size()); 290 memcpy(buffer, chunk_description.data(), chunk_description.size());
297 memcpy(buffer + chunk_description.size(), data, len); 291 memcpy(buffer + chunk_description.size(), data, len);
298 memcpy(buffer + chunk_description.size() + len, "\r\n", 2); 292 memcpy(buffer + chunk_description.size() + len, "\r\n", 2);
299 EnqueueDataFrame(df); 293 EnqueueDataFrame(df);
300 } 294 }
301 295
302 void HttpSM::EnqueueDataFrame(DataFrame* df) { 296 void HttpSM::EnqueueDataFrame(DataFrame* df) {
303 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: Enqueue data frame: stream " 297 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: Enqueue data frame: stream "
304 << stream_id_; 298 << stream_id_;
305 connection_->EnqueueDataFrame(df); 299 connection_->EnqueueDataFrame(df);
306 } 300 }
307 301
308 void HttpSM::GetOutput() { 302 void HttpSM::GetOutput() {
309 MemCacheIter* mci = output_ordering_.GetIter(); 303 MemCacheIter* mci = output_ordering_.GetIter();
310 if (mci == NULL) { 304 if (mci == NULL) {
311 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: GetOutput: nothing to " 305 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: GetOutput: nothing to "
312 << "output!?: stream " << stream_id_; 306 << "output!?: stream " << stream_id_;
313 return; 307 return;
314 } 308 }
315 if (!mci->transformed_header) { 309 if (!mci->transformed_header) {
316 mci->bytes_sent = SendSynReply(mci->stream_id, 310 mci->bytes_sent =
317 *(mci->file_data->headers())); 311 SendSynReply(mci->stream_id, *(mci->file_data->headers()));
318 mci->transformed_header = true; 312 mci->transformed_header = true;
319 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: GetOutput transformed " 313 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: GetOutput transformed "
320 << "header stream_id: [" << mci->stream_id << "]"; 314 << "header stream_id: [" << mci->stream_id << "]";
321 return; 315 return;
322 } 316 }
323 if (mci->body_bytes_consumed >= mci->file_data->body().size()) { 317 if (mci->body_bytes_consumed >= mci->file_data->body().size()) {
324 SendEOF(mci->stream_id); 318 SendEOF(mci->stream_id);
325 output_ordering_.RemoveStreamId(mci->stream_id); 319 output_ordering_.RemoveStreamId(mci->stream_id);
326 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "GetOutput remove_stream_id: [" 320 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "GetOutput remove_stream_id: ["
327 << mci->stream_id << "]"; 321 << mci->stream_id << "]";
328 return; 322 return;
329 } 323 }
330 size_t num_to_write = 324 size_t num_to_write =
331 mci->file_data->body().size() - mci->body_bytes_consumed; 325 mci->file_data->body().size() - mci->body_bytes_consumed;
332 if (num_to_write > mci->max_segment_size) 326 if (num_to_write > mci->max_segment_size)
333 num_to_write = mci->max_segment_size; 327 num_to_write = mci->max_segment_size;
334 328
335 SendDataFrame(mci->stream_id, 329 SendDataFrame(mci->stream_id,
336 mci->file_data->body().data() + mci->body_bytes_consumed, 330 mci->file_data->body().data() + mci->body_bytes_consumed,
337 num_to_write, 0, true); 331 num_to_write,
332 0,
333 true);
338 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: GetOutput SendDataFrame[" 334 VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpSM: GetOutput SendDataFrame["
339 << mci->stream_id << "]: " << num_to_write; 335 << mci->stream_id << "]: " << num_to_write;
340 mci->body_bytes_consumed += num_to_write; 336 mci->body_bytes_consumed += num_to_write;
341 mci->bytes_sent += num_to_write; 337 mci->bytes_sent += num_to_write;
342 } 338 }
343 339
344 } // namespace net 340 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/flip_server/http_interface.h ('k') | net/tools/flip_server/http_interface_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698