Skip to content

Commit

Permalink
Make Proxygen server open source
Browse files Browse the repository at this point in the history
Summary: This is the Proxygen server used to serve http requests within Facebook

Reviewed By: @afrind

Differential Revision: D1902536
  • Loading branch information
ckwalsh authored and hhvm-bot committed Apr 23, 2015
1 parent 5ea6c10 commit 8039dc9
Show file tree
Hide file tree
Showing 7 changed files with 2,066 additions and 3 deletions.
11 changes: 8 additions & 3 deletions hphp/runtime/CMakeLists.txt
Expand Up @@ -18,10 +18,15 @@ if(NOT ENABLE_FASTCGI)
endforeach(file ${CXX_SOURCES})
endif()

if(NOT ENABLE_PROXYGEN_SERVER)
foreach (file ${CXX_SOURCES})
if (${file} MATCHES "/proxygen/")
list(REMOVE_ITEM CXX_SOURCES ${file})
endif()
endforeach(file ${CXX_SOURCES})
endif()

if(NOT HAVE_CUSTOM_LIBEVENT)
# Not working with off-the-shelf libevent
list(REMOVE_ITEM CXX_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/server/server-name-indication.cpp")
foreach (file ${CXX_SOURCES})
if(${file} MATCHES "/server/libevent-")
list(REMOVE_ITEM CXX_SOURCES ${file})
Expand Down
100 changes: 100 additions & 0 deletions hphp/runtime/server/fake-transport.h
@@ -0,0 +1,100 @@
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/

#ifndef incl_HPHP_FAKE_TRANSPORT_H_
#define incl_HPHP_FAKE_TRANSPORT_H_

#include "hphp/runtime/server/transport.h"

namespace HPHP {

/**
* Fake Transport to be passed to the access log when a real transport is not
* available
*/
class FakeTransport : public Transport {
public:
std::string m_url;
std::string m_remoteHost;
uint16_t m_remotePort{0};
int m_requestSize{0};
Method m_method{Method::GET};
std::string m_extended_method;
std::string m_httpVersion{"1.1"};

explicit FakeTransport(uint16_t code) {
m_responseCode = code;
}

/**
* Request URI.
*/
virtual const char *getUrl() { return m_url.c_str(); }
virtual const char *getRemoteHost() { return m_remoteHost.c_str(); }
virtual uint16_t getRemotePort() { return m_remotePort; }
virtual int getRequestSize() const { return m_requestSize; }

/**
* POST request's data.
*/
virtual const void *getPostData(int &size) {
LOG(FATAL) << "FakeTransport::getPostData";
size = 0;
return nullptr;
}

virtual Method getMethod() { return m_method; }
virtual const char *getExtendedMethod() { return m_extended_method.c_str();}

/**
* What version of HTTP was the request?
*/
virtual std::string getHTTPVersion() const {
return m_httpVersion.c_str();
}

/**
* Get request header(s).
*/
virtual std::string getHeader(const char *name) {
return "";
};
virtual void getHeaders(HeaderMap &headers) {
LOG(FATAL) << "FakeTransport::getHeaders";
}
/**
* Add/remove a response header.
*/
virtual void addHeaderImpl(const char *name, const char *value) {
LOG(FATAL) << "FakeTransport::addHeaderImpl";
};
virtual void removeHeaderImpl(const char *name) {
LOG(FATAL) << "FakeTransport::removeHeaderImpl";
}

/**
* Send back a response with specified code.
* Caller deletes data, callee must copy
*/
virtual void sendImpl(const void *data, int size, int code,
bool chunked, bool eom) {
LOG(FATAL) << "FakeTransport::sendImpl";
};

};

}
#endif
44 changes: 44 additions & 0 deletions hphp/runtime/server/proxygen/proxygen-server-factory.cpp
@@ -0,0 +1,44 @@
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/

#include "hphp/runtime/server/proxygen/proxygen-server.h"

namespace HPHP {

class ProxygenServerFactory : public ServerFactory {
public:
ProxygenServerFactory() {}

virtual ServerPtr createServer(const ServerOptions& options) override {
return folly::make_unique<ProxygenServer>(options);
}
};

}

extern "C" {

/*
* Automatically register ProxygenServerFactory on program start
*/
void register_proxygen_server() __attribute__((__constructor__));
void register_proxygen_server() {
auto registry = HPHP::ServerFactoryRegistry::getInstance();
auto factory = std::make_shared<HPHP::ProxygenServerFactory>();
registry->registerFactory("proxygen", factory);
}

}

1 comment on commit 8039dc9

@simonwelsh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Please sign in to comment.