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

Unified Diff: chrome/browser/chromeos/gdata/test_servers/http_connection.cc

Issue 11088073: HTTP server for testing Google Drive. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added the forgotten file. Created 8 years, 2 months 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 side-by-side diff with in-line comments
Download patch
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..c9c637e4bf63458b76df5b789a40caf008c1dc99
--- /dev/null
+++ b/chrome/browser/chromeos/gdata/test_servers/http_connection.cc
@@ -0,0 +1,64 @@
+// 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 <sstream>
+#include "base/basictypes.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) {
+}
+
+HttpConnection::~HttpConnection() {
+
+}
+
+void HttpConnection::SendResponse(scoped_ptr<HttpResponse> response) {
+ // TODO(mtomasz): This is just a stub. Replace with better response sending.
+
+ // Response line with headers.
+ 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.
+ response_builder << "HTTP/1.1 " << response->code << " OK\r\n";
+ std::map<std::string, std::string>::iterator it;
+ response_builder << "Content-Length: "
+ << response->content.length() << "\r\n";
+ response_builder << "Content-Type: " << response->content_type << "\r\n";
+ for (it = response->custom_headers.begin();
+ it != response->custom_headers.end();
+ it++) {
+ response_builder << it->first << ": " << it->second << "\r\n";
+ }
+ response_builder << "\r\n";
+ std::string response_text = response_builder.str();
+ socket_->Send(response_text.c_str(), response_text.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()) ==
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.
+ 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
+ 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

Powered by Google App Engine
This is Rietveld 408576698