Skip to content

Instantly share code, notes, and snippets.

@mundry
Last active February 29, 2016 18:17
Show Gist options
  • Save mundry/9067736ad07e95c73db0 to your computer and use it in GitHub Desktop.
Save mundry/9067736ad07e95c73db0 to your computer and use it in GitHub Desktop.
Patch to make HHVM's expose_hphp config setting more granular.
diff --git a/hphp/runtime/base/runtime-option.cpp b/hphp/runtime/base/runtime-option.cpp
index 3a3d25a..9903996 100644
--- a/hphp/runtime/base/runtime-option.cpp
+++ b/hphp/runtime/base/runtime-option.cpp
@@ -179,7 +179,7 @@ std::string RuntimeOption::ForceCompressionURL;
std::string RuntimeOption::ForceCompressionCookie;
std::string RuntimeOption::ForceCompressionParam;
bool RuntimeOption::EnableKeepAlive = true;
-bool RuntimeOption::ExposeHPHP = true;
+std::string RuntimeOption::ExposeHPHP = "full";
bool RuntimeOption::ExposeXFBServer = false;
bool RuntimeOption::ExposeXFBDebug = false;
std::string RuntimeOption::XFBDebugSSLKey;
@@ -1292,7 +1292,7 @@ void RuntimeOption::Load(
Config::Bind(ForceCompressionParam, ini, config,
"Server.ForceCompression.Param");
Config::Bind(EnableKeepAlive, ini, config, "Server.EnableKeepAlive", true);
- Config::Bind(ExposeHPHP, ini, config, "Server.ExposeHPHP", true);
+ Config::Bind(ExposeHPHP, ini, config, "Server.ExposeHPHP", "full");
Config::Bind(ExposeXFBServer, ini, config, "Server.ExposeXFBServer", false);
Config::Bind(ExposeXFBDebug, ini, config, "Server.ExposeXFBDebug", false);
Config::Bind(XFBDebugSSLKey, ini, config, "Server.XFBDebugSSLKey", "");
diff --git a/hphp/runtime/base/runtime-option.h b/hphp/runtime/base/runtime-option.h
index 3c220ef..37aad2d 100644
--- a/hphp/runtime/base/runtime-option.h
+++ b/hphp/runtime/base/runtime-option.h
@@ -161,7 +161,7 @@ struct RuntimeOption {
static std::string ForceCompressionCookie;
static std::string ForceCompressionParam;
static bool EnableKeepAlive;
- static bool ExposeHPHP;
+ static std::string ExposeHPHP;
static bool ExposeXFBServer;
static bool ExposeXFBDebug;
static std::string XFBDebugSSLKey;
diff --git a/hphp/runtime/server/transport.cpp b/hphp/runtime/server/transport.cpp
index 8e56807..bfcde8b 100644
--- a/hphp/runtime/server/transport.cpp
+++ b/hphp/runtime/server/transport.cpp
@@ -17,6 +17,7 @@
#include "hphp/runtime/server/transport.h"
#include <boost/algorithm/string.hpp>
+#include <boost/preprocessor/stringize.hpp>
#include "hphp/runtime/server/server.h"
#include "hphp/runtime/server/upload.h"
@@ -741,8 +742,25 @@ void Transport::prepareHeaders(bool compressed, bool chunked,
addHeaderImpl("Content-Type", contentType.c_str());
}
- if (RuntimeOption::ExposeHPHP) {
+ if (RuntimeOption::ExposeHPHP == "full") {
addHeaderImpl("X-Powered-By", (String("HHVM/") + HHVM_VERSION).c_str());
+ } else if (RuntimeOption::ExposeHPHP == "name") {
+ addHeaderImpl("X-Powered-By", (String("HHVM")).c_str());
+ } else if (RuntimeOption::ExposeHPHP == "major") {
+ addHeaderImpl("X-Powered-By",
+ (String("HHVM/") +
+ BOOST_PP_STRINGIZE(HHVM_VERSION_MAJOR)).c_str());
+ } else if (RuntimeOption::ExposeHPHP == "minor") {
+ addHeaderImpl("X-Powered-By",
+ (String("HHVM/") +
+ BOOST_PP_STRINGIZE(HHVM_VERSION_MAJOR) "."
+ BOOST_PP_STRINGIZE(HHVM_VERSION_MINOR)).c_str());
+ } else if (RuntimeOption::ExposeHPHP == "patch") {
+ addHeaderImpl("X-Powered-By",
+ (String("HHVM/") +
+ BOOST_PP_STRINGIZE(HHVM_VERSION_MAJOR) "."
+ BOOST_PP_STRINGIZE(HHVM_VERSION_MINOR) "."
+ BOOST_PP_STRINGIZE(HHVM_VERSION_PATCH)).c_str());
}
if ((RuntimeOption::ExposeXFBServer || RuntimeOption::ExposeXFBDebug) &&

Usage

hhvm.server.expose_hphp = full|name|major|minor|patch|off

Values

The following values set the X-Powered-By HTTP response header to different levels of version detail.

full

The full version info. e.g.: HHVM/3.12.0, HHVM/3.12.0-dev or as defined with -DHHVM_VERSION_OVERRIDE
This is the default value if the setting is omitted.

name

The name HHVM

major

The name and the major version. e.g.: HHVM/3

minor

The name and the major and minor version. e.g.: HHVM/3.12

patch

The name, the major, minor and patch version. e.g.: HHVM/3.12.0

off

Removes the X-Powered-By HTTP header from the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment