summaryrefslogtreecommitdiffstats
path: root/net/tools
diff options
context:
space:
mode:
authormbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-28 21:56:19 +0000
committermbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-28 21:56:19 +0000
commitf5843421ecfbc7e0ef4ae6878d110d5fd50ff75f (patch)
tree1ba342709f915f4274d6e7dbe7d4102411c929f2 /net/tools
parent1b8af731dccaaf3b040e32481aedf9e113f32854 (diff)
downloadchromium_src-f5843421ecfbc7e0ef4ae6878d110d5fd50ff75f.zip
chromium_src-f5843421ecfbc7e0ef4ae6878d110d5fd50ff75f.tar.gz
chromium_src-f5843421ecfbc7e0ef4ae6878d110d5fd50ff75f.tar.bz2
Patch from kelindsay@gmail.com
Misc fixes: * The forward-for header was not being added to non-spdy https traffic. * Fix a memory leak Review URL: http://codereview.chromium.org/6541078 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76264 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools')
-rw-r--r--net/tools/flip_server/flip_in_mem_edsm_server.cc3
-rw-r--r--net/tools/flip_server/http_interface.h1
-rw-r--r--net/tools/flip_server/sm_connection.cc4
-rw-r--r--net/tools/flip_server/sm_interface.h1
-rw-r--r--net/tools/flip_server/spdy_interface.cc1
-rw-r--r--net/tools/flip_server/spdy_interface.h1
-rw-r--r--net/tools/flip_server/streamer_interface.cc81
-rw-r--r--net/tools/flip_server/streamer_interface.h54
8 files changed, 137 insertions, 9 deletions
diff --git a/net/tools/flip_server/flip_in_mem_edsm_server.cc b/net/tools/flip_server/flip_in_mem_edsm_server.cc
index 4c32311..f8abfb7 100644
--- a/net/tools/flip_server/flip_in_mem_edsm_server.cc
+++ b/net/tools/flip_server/flip_in_mem_edsm_server.cc
@@ -22,6 +22,7 @@
#include "net/tools/flip_server/sm_connection.h"
#include "net/tools/flip_server/sm_interface.h"
#include "net/tools/flip_server/spdy_interface.h"
+#include "net/tools/flip_server/streamer_interface.h"
#include "net/tools/flip_server/split.h"
using std::cout;
@@ -219,6 +220,8 @@ int main (int argc, char**argv)
if (cl.HasSwitch("forward-ip-header")) {
net::SpdySM::set_forward_ip_header(
cl.GetSwitchValueASCII("forward-ip-header"));
+ net::StreamerSM::set_forward_ip_header(
+ cl.GetSwitchValueASCII("forward-ip-header"));
}
if (cl.HasSwitch("logdest")) {
diff --git a/net/tools/flip_server/http_interface.h b/net/tools/flip_server/http_interface.h
index ce5185e..fa9ceb4 100644
--- a/net/tools/flip_server/http_interface.h
+++ b/net/tools/flip_server/http_interface.h
@@ -69,6 +69,7 @@ class HttpSM : public BalsaVisitorInterface,
void AddToOutputOrder(const MemCacheIter& mci);
void SendOKResponse(uint32 stream_id, std::string* output);
BalsaFrame* spdy_framer() { return http_framer_; }
+ void set_is_request() {}
// SMInterface:
virtual void InitSMInterface(SMInterface* sm_spdy_interface,
diff --git a/net/tools/flip_server/sm_connection.cc b/net/tools/flip_server/sm_connection.cc
index b1dc3c8..b57c5a9 100644
--- a/net/tools/flip_server/sm_connection.cc
+++ b/net/tools/flip_server/sm_connection.cc
@@ -362,11 +362,13 @@ bool SMConnection::SetupProtocolInterfaces() {
VLOG(2) << log_prefix_ << ACCEPTOR_CLIENT_IDENT
<< (sm_streamer_interface_ ? "Creating" : "Reusing")
<< " PROXY Streamer interface.";
- if (!sm_streamer_interface_)
+ if (!sm_streamer_interface_) {
sm_streamer_interface_ = new StreamerSM(this,
NULL,
epoll_server_,
acceptor_);
+ sm_streamer_interface_->set_is_request();
+ }
sm_interface_ = sm_streamer_interface_;
// If spdy is not negotiated, the streamer interface will proxy all
// data to the origin server.
diff --git a/net/tools/flip_server/sm_interface.h b/net/tools/flip_server/sm_interface.h
index 29196cf..5bc942f 100644
--- a/net/tools/flip_server/sm_interface.h
+++ b/net/tools/flip_server/sm_interface.h
@@ -57,6 +57,7 @@ class SMInterface {
virtual void SendDataFrame(uint32 stream_id, const char* data, int64 len,
uint32 flags, bool compress) = 0;
virtual void GetOutput() = 0;
+ virtual void set_is_request() = 0;
virtual ~SMInterface() {}
};
diff --git a/net/tools/flip_server/spdy_interface.cc b/net/tools/flip_server/spdy_interface.cc
index c6149b8..8136ebd 100644
--- a/net/tools/flip_server/spdy_interface.cc
+++ b/net/tools/flip_server/spdy_interface.cc
@@ -390,6 +390,7 @@ void SpdySM::SendEOFImpl(uint32 stream_id) {
SendDataFrame(stream_id, NULL, 0, DATA_FLAG_FIN, false);
VLOG(2) << ACCEPTOR_CLIENT_IDENT << "SpdySM: Sending EOF: " << stream_id;
KillStream(stream_id);
+ stream_to_smif_.erase(stream_id);
}
void SpdySM::SendErrorNotFoundImpl(uint32 stream_id) {
diff --git a/net/tools/flip_server/spdy_interface.h b/net/tools/flip_server/spdy_interface.h
index 64b397d..f407d2e 100644
--- a/net/tools/flip_server/spdy_interface.h
+++ b/net/tools/flip_server/spdy_interface.h
@@ -51,6 +51,7 @@ class SpdySM : public spdy::SpdyFramerVisitorInterface,
}
private:
+ virtual void set_is_request() {}
virtual void OnError(spdy::SpdyFramer* framer) {}
SMInterface* NewConnectionInterface();
SMInterface* FindOrMakeNewSMConnectionInterface(std::string server_ip,
diff --git a/net/tools/flip_server/streamer_interface.cc b/net/tools/flip_server/streamer_interface.cc
index bbcb69a..62ca712 100644
--- a/net/tools/flip_server/streamer_interface.cc
+++ b/net/tools/flip_server/streamer_interface.cc
@@ -6,12 +6,15 @@
#include <string>
+#include "net/tools/flip_server/balsa_frame.h"
#include "net/tools/flip_server/constants.h"
#include "net/tools/flip_server/flip_config.h"
#include "net/tools/flip_server/sm_connection.h"
namespace net {
+std::string StreamerSM::forward_ip_header_;
+
StreamerSM::StreamerSM(SMConnection* connection,
SMInterface* sm_other_interface,
EpollServer* epoll_server,
@@ -19,13 +22,24 @@ StreamerSM::StreamerSM(SMConnection* connection,
: connection_(connection),
sm_other_interface_(sm_other_interface),
epoll_server_(epoll_server),
- acceptor_(acceptor) {
+ acceptor_(acceptor),
+ is_request_(false),
+ http_framer_(new BalsaFrame) {
VLOG(2) << ACCEPTOR_CLIENT_IDENT << "Creating StreamerSM object";
+ http_framer_->set_balsa_visitor(this);
+ http_framer_->set_balsa_headers(&headers_);
+ http_framer_->set_is_request(false);
}
StreamerSM::~StreamerSM() {
VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Destroying StreamerSM object";
Reset();
+ delete http_framer_;
+}
+
+void StreamerSM::set_is_request() {
+ is_request_ = true;
+ http_framer_->set_is_request(true);
}
void StreamerSM::InitSMInterface(SMInterface* sm_other_interface,
@@ -49,7 +63,12 @@ void StreamerSM::InitSMConnection(SMConnectionPoolInterface* connection_pool,
}
size_t StreamerSM::ProcessReadInput(const char* data, size_t len) {
- return sm_other_interface_->ProcessWriteInput(data, len);
+ // For now we only want to parse http requests. Just stream responses
+ if (is_request_) {
+ return http_framer_->ProcessInput(data, len);
+ } else {
+ return sm_other_interface_->ProcessWriteInput(data, len);
+ }
}
size_t StreamerSM::ProcessWriteInput(const char* data, size_t len) {
@@ -63,10 +82,6 @@ size_t StreamerSM::ProcessWriteInput(const char* data, size_t len) {
return len;
}
-bool StreamerSM::MessageFullyRead() const {
- return false;
-}
-
bool StreamerSM::Error() const {
return false;
}
@@ -75,15 +90,30 @@ const char* StreamerSM::ErrorAsString() const {
return "(none)";
}
+bool StreamerSM::MessageFullyRead() const {
+ if (is_request_) {
+ return http_framer_->MessageFullyRead();
+ } else {
+ return false;
+ }
+}
+
void StreamerSM::Reset() {
VLOG(1) << ACCEPTOR_CLIENT_IDENT << "StreamerSM: Reset";
connection_->Cleanup("Server Reset");
+ http_framer_->Reset();
}
void StreamerSM::ResetForNewConnection() {
+ http_framer_->Reset();
sm_other_interface_->Reset();
}
+void StreamerSM::Cleanup() {
+ if (is_request_)
+ http_framer_->Reset();
+}
+
int StreamerSM::PostAcceptHook() {
if (!sm_other_interface_) {
SMConnection *server_connection =
@@ -120,5 +150,44 @@ size_t StreamerSM::SendSynReply(uint32 stream_id, const BalsaHeaders& headers) {
return 0;
}
+void StreamerSM::ProcessBodyInput(const char *input, size_t size) {
+ VLOG(2) << ACCEPTOR_CLIENT_IDENT
+ << "StreamerHttpSM: Process Body Input Data: "
+ << "size " << size;
+ sm_other_interface_->ProcessWriteInput(input, size);
+}
+
+void StreamerSM::MessageDone() {
+ if (acceptor_->flip_handler_type_ == FLIP_HANDLER_PROXY) {
+ VLOG(2) << ACCEPTOR_CLIENT_IDENT << "StreamerHttpSM: MessageDone.";
+ // TODO(kelindsay): anything need to be done ehre?
+ } else {
+ VLOG(2) << ACCEPTOR_CLIENT_IDENT << "StraemerHttpSM: MessageDone.";
+ }
+}
+
+void StreamerSM::ProcessHeaders(const BalsaHeaders& headers) {
+ VLOG(2) << ACCEPTOR_CLIENT_IDENT << "HttpStreamerSM: Process Headers";
+ BalsaHeaders mod_headers;
+ mod_headers.CopyFrom(headers);
+ if (forward_ip_header_.length()) {
+ LOG(INFO) << "Adding forward header: " << forward_ip_header_;
+ mod_headers.ReplaceOrAppendHeader(forward_ip_header_,
+ connection_->client_ip());
+ } else {
+ LOG(INFO) << "NOT adding forward header.";
+ }
+ SimpleBuffer sb;
+ char* buffer;
+ int size;
+ mod_headers.WriteHeaderAndEndingToBuffer(&sb);
+ sb.GetReadablePtr(&buffer, &size);
+ sm_other_interface_->ProcessWriteInput(buffer, size);
+}
+
+void StreamerSM::HandleError() {
+ VLOG(1) << ACCEPTOR_CLIENT_IDENT << "Error detected";
+}
+
} // namespace net
diff --git a/net/tools/flip_server/streamer_interface.h b/net/tools/flip_server/streamer_interface.h
index de3dd94..39df15e 100644
--- a/net/tools/flip_server/streamer_interface.h
+++ b/net/tools/flip_server/streamer_interface.h
@@ -7,16 +7,20 @@
#include <string>
+#include "net/tools/flip_server/balsa_headers.h"
+#include "net/tools/flip_server/balsa_visitor_interface.h"
#include "net/tools/flip_server/sm_interface.h"
namespace net {
+class BalsaFrame;
class FlipAcceptor;
class MemCacheIter;
class SMConnection;
class EpollServer;
-class StreamerSM : public SMInterface {
+class StreamerSM : public BalsaVisitorInterface,
+ public SMInterface {
public:
StreamerSM(SMConnection* connection,
SMInterface* sm_other_interface,
@@ -46,7 +50,7 @@ class StreamerSM : public SMInterface {
virtual void Reset();
virtual void ResetForNewInterface(int32 server_idx) {}
virtual void ResetForNewConnection();
- virtual void Cleanup() {}
+ virtual void Cleanup();
virtual int PostAcceptHook();
virtual void NewStream(uint32 stream_id, uint32 priority,
const std::string& filename) {}
@@ -57,6 +61,11 @@ class StreamerSM : public SMInterface {
virtual size_t SendSynReply(uint32 stream_id, const BalsaHeaders& headers);
virtual void SendDataFrame(uint32 stream_id, const char* data, int64 len,
uint32 flags, bool compress) {}
+ void set_is_request();
+ static std::string forward_ip_header() { return forward_ip_header_; }
+ static void set_forward_ip_header(std::string value) {
+ forward_ip_header_ = value;
+ }
private:
void SendEOFImpl(uint32 stream_id) {}
@@ -72,10 +81,51 @@ class StreamerSM : public SMInterface {
uint32 flags, bool compress) {}
virtual void GetOutput() {}
+ virtual void ProcessBodyInput(const char *input, size_t size);
+ virtual void MessageDone();
+ virtual void ProcessHeaders(const BalsaHeaders& headers);
+ virtual void ProcessBodyData(const char *input, size_t size) {}
+ virtual void ProcessHeaderInput(const char *input, size_t size) {}
+ virtual void ProcessTrailerInput(const char *input, size_t size) {}
+ virtual void ProcessRequestFirstLine(const char* line_input,
+ size_t line_length,
+ const char* method_input,
+ size_t method_length,
+ const char* request_uri_input,
+ size_t request_uri_length,
+ const char* version_input,
+ size_t version_length) {}
+ virtual void ProcessResponseFirstLine(const char *line_input,
+ size_t line_length,
+ const char *version_input,
+ size_t version_length,
+ const char *status_input,
+ size_t status_length,
+ const char *reason_input,
+ size_t reason_length) {}
+ virtual void ProcessChunkLength(size_t chunk_length) {}
+ virtual void ProcessChunkExtensions(const char *input, size_t size) {}
+ virtual void HeaderDone() {}
+ virtual void HandleHeaderError(BalsaFrame* framer) {
+ HandleError();
+ }
+ virtual void HandleHeaderWarning(BalsaFrame* framer) {}
+ virtual void HandleChunkingError(BalsaFrame* framer) {
+ HandleError();
+ }
+ virtual void HandleBodyError(BalsaFrame* framer) {
+ HandleError();
+ }
+ void HandleError();
+
SMConnection* connection_;
SMInterface* sm_other_interface_;
EpollServer* epoll_server_;
FlipAcceptor* acceptor_;
+ bool is_request_;
+ BalsaFrame* http_framer_;
+ BalsaHeaders headers_;
+ static std::string forward_ip_header_;
};
} // namespace net