OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/chromeos/gdata/test_servers/http_connection.h" | |
6 | |
7 #include <string> | |
8 #include <sstream> | |
9 #include "base/basictypes.h" | |
10 #include "chrome/browser/chromeos/gdata/test_servers/http_request.h" | |
11 #include "chrome/browser/chromeos/gdata/test_servers/http_response.h" | |
12 | |
13 namespace gdata { | |
14 namespace test_servers { | |
15 | |
16 HttpConnection::HttpConnection(net::StreamListenSocket* socket, | |
17 HttpConnectionDelegate* delegate) : | |
18 socket_(socket), | |
19 delegate_(delegate) { | |
20 } | |
21 | |
22 HttpConnection::~HttpConnection() { | |
23 | |
24 } | |
25 | |
26 void HttpConnection::SendResponse(scoped_ptr<HttpResponse> response) { | |
27 // TODO(mtomasz): This is just a stub. Replace with better response sending. | |
28 | |
29 // Response line with headers. | |
30 std::stringstream response_builder; | |
satorux1
2012/10/12 08:29:18
like google3, we don't use streams. Please use Str
mtomasz
2012/10/12 11:09:46
Done.
| |
31 response_builder << "HTTP/1.1 " << response->code << " OK\r\n"; | |
32 std::map<std::string, std::string>::iterator it; | |
33 response_builder << "Content-Length: " | |
34 << response->content.length() << "\r\n"; | |
35 response_builder << "Content-Type: " << response->content_type << "\r\n"; | |
36 for (it = response->custom_headers.begin(); | |
37 it != response->custom_headers.end(); | |
38 it++) { | |
39 response_builder << it->first << ": " << it->second << "\r\n"; | |
40 } | |
41 response_builder << "\r\n"; | |
42 std::string response_text = response_builder.str(); | |
43 socket_->Send(response_text.c_str(), response_text.length()); | |
44 | |
45 // Response content. | |
46 socket_->Send(response->content.c_str(), response->content.length()); | |
47 } | |
48 | |
49 bool HttpConnection::ReceiveData(const char* data, int length) { | |
50 request_parser_.ProcessChunk(data, length); | |
51 HttpRequestParser::STATE parser_state; | |
52 while ((parser_state = request_parser_.ParseRequest()) == | |
satorux1
2012/10/12 08:29:18
assignment in while() looks a bit tricky. maybe ju
mtomasz
2012/10/12 11:09:46
I know that this while is non-trivial, but persona
satorux1
2012/10/16 03:12:18
Then that's fine.
| |
53 HttpRequestParser::READY) { | |
satorux1
2012/10/12 08:29:18
indentation is off? should look like:
while ((par
mtomasz
2012/10/12 11:09:46
Here I made a 4-spaces indentation as for too long
satorux1
2012/10/16 03:12:18
In conditionals, we should align vertically.
satorux1
2012/10/16 03:19:25
Not only in conditionals, if stuff in parens is lo
| |
54 if (!delegate_->HandleRequest(*this, request_parser_.GetRequest().Pass())) { | |
55 // Delegate did not accept the request, so we will drop the connection. | |
56 return false; | |
57 } | |
58 } | |
59 // If syntax error occured, then we drop the connection. | |
60 return parser_state != HttpRequestParser::SYNTAX_ERROR; | |
61 } | |
62 | |
63 } // namespace test_servers | |
64 } // namespace gdata | |
OLD | NEW |