Chromium Code Reviews| Index: chrome/browser/chromeos/gdata/test_servers/http_connection.cc |
| diff --git a/chrome/browser/chromeos/gdata/test_servers/http_connection.cc b/chrome/browser/chromeos/gdata/test_servers/http_connection.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f83690f84894c802b0b71184464a42ca551128fc |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/gdata/test_servers/http_connection.cc |
| @@ -0,0 +1,69 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/gdata/test_servers/http_connection.h" |
| + |
| +#include <string> |
| +#include "base/basictypes.h" |
| +#include "base/stringprintf.h" |
| +#include "chrome/browser/chromeos/gdata/test_servers/http_request.h" |
| +#include "chrome/browser/chromeos/gdata/test_servers/http_response.h" |
| + |
| +namespace gdata { |
| +namespace test_servers { |
| + |
| +HttpConnection::HttpConnection(net::StreamListenSocket* socket, |
| + HttpConnectionDelegate* delegate) : |
| + socket_(socket), |
| + delegate_(delegate) { |
|
satorux1
2012/10/16 03:12:18
indentation is awkward. please do this:
HttpConne
mtomasz
2012/11/08 13:29:59
Done.
|
| +} |
| + |
| +HttpConnection::~HttpConnection() { |
| + |
| +} |
| + |
| +void HttpConnection::SendResponse(scoped_ptr<HttpResponse> response) { |
| + // TODO(mtomasz): This is just a stub. Replace with a better response sending. |
| + |
| + // Response line with headers. |
| + std::string response_builder; |
| + base::StringAppendF(&response_builder, "HTTP/1.1 %d OK\r\n", response->code); |
| + std::map<std::string, std::string>::iterator it; |
| + base::StringAppendF(&response_builder, |
| + "Content-Length: %lu\r\n", |
| + response->content.length()); |
|
satorux1
2012/10/16 03:12:18
Is length() 64-bit? If so %lu is not correct. See
mtomasz
2012/11/08 13:29:59
Done.
|
| + base::StringAppendF(&response_builder, |
| + "Content-Type: %s\r\n", |
| + response->content_type.c_str()); |
| + for (it = response->custom_headers.begin(); |
|
satorux1
2012/10/16 03:12:18
Can you declare it here?
for (std::map<std::stri
mtomasz
2012/11/08 13:29:59
Done.
|
| + it != response->custom_headers.end(); |
| + it++) { |
| + base::StringAppendF(&response_builder, |
| + "%s: %s\r\n", |
| + it->first.c_str(), |
| + it->second.c_str()); |
| + } |
| + base::StringAppendF(&response_builder, "\r\n"); |
| + socket_->Send(response_builder.c_str(), response_builder.length()); |
| + |
| + // Response content. |
| + socket_->Send(response->content.c_str(), response->content.length()); |
| +} |
| + |
| +bool HttpConnection::ReceiveData(const char* data, int length) { |
| + request_parser_.ProcessChunk(data, length); |
| + HttpRequestParser::STATE parser_state; |
| + while ((parser_state = request_parser_.ParseRequest()) == |
| + HttpRequestParser::READY) { |
| + if (!delegate_->HandleRequest(*this, request_parser_.GetRequest().Pass())) { |
| + // Delegate did not accept the request, so we will drop the connection. |
| + return false; |
| + } |
| + } |
| + // If syntax error occured, then we drop the connection. |
| + return parser_state != HttpRequestParser::SYNTAX_ERROR; |
| +} |
| + |
| +} // namespace test_servers |
| +} // namespace gdata |