Skip to content

Commit ee94679

Browse files
committed
Support compressing static assets
HHVM has support for serving static assets via the builtin server, but they're always served uncompressed. It would be valuable if these responses were compressed in some development setups. So, introduce a new runtime option `Server.AllowStaticAssetsCompression` that defaults to `false` and allows on-the-fly compression of static assets if enabled. Remove the confusing `compressed` parameter from `sendStaticContent` as it appears to have been once used to indicate whether the content was precompressed but is now always `false`.
1 parent b43c056 commit ee94679

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

hphp/doc/configs.specification

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ The format can be found in hphp/tools/configs/generate_configs.rs
318318
- int Server.GzipMaxCompressionLevel = 9, UNKNOWN
319319
- bool Server.GzipUseLocalArena = false, UNKNOWN
320320

321+
Enable compression of static assets served by HHVM
322+
323+
- bool Server.AllowStaticAssetsCompression = false, UNKNOWN
324+
321325
Enable additional for config.hdf overwrite inputs to scuba:hhvm_config_hdf_logs (eg. machine, cpu, tier, tag etc)
322326

323327
- bool Server.LogTierOverwriteInputs = false, ffledgling

hphp/runtime/server/http-request-handler.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ HttpRequestHandler::HttpRequestHandler(int timeout)
140140
void HttpRequestHandler::sendStaticContent(Transport *transport,
141141
const char *data, int len,
142142
time_t mtime,
143-
bool compressed,
144143
const std::string &cmd,
145144
const char *ext) {
146145
assertx(ext);
@@ -194,9 +193,11 @@ void HttpRequestHandler::sendStaticContent(Transport *transport,
194193

195194
// misnomer, it means we have made decision on compression, transport
196195
// should not attempt to compress it.
197-
transport->disableCompression();
196+
if (!Cfg::Server::AllowStaticAssetsCompression) {
197+
transport->disableCompression();
198+
}
198199

199-
transport->sendRaw(data, len, 200, compressed);
200+
transport->sendRaw(data, len, 200, false);
200201
transport->onSendEnd();
201202
}
202203

@@ -337,7 +338,7 @@ void HttpRequestHandler::handleRequest(Transport *transport) {
337338
// local cache file is not valuable, maybe misleading. This way
338339
// the Last-Modified header will not show in response.
339340
// stat(Cfg::Server::FileCache.c_str(), &st);
340-
sendStaticContent(transport, content->buffer, content->size, 0, false,
341+
sendStaticContent(transport, content->buffer, content->size, 0,
341342
path, ext);
342343
ServerStats::LogPage(path, 200);
343344
return;
@@ -639,7 +640,7 @@ bool HttpRequestHandler::handleFileRequest(Transport* transport,
639640
::close(fd);
640641
buffer[len] = 0;
641642
sendStaticContent(transport, buffer, len, stat_buf.st_mtime,
642-
false, path, ext);
643+
path, ext);
643644
ServerStats::LogPage(path, 200);
644645
return true;
645646
}

hphp/runtime/server/http-request-handler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct HttpRequestHandler : RequestHandler {
6262
const std::string& path, const char* ext);
6363
bool handleProxyRequest(Transport *transport, bool force);
6464
void sendStaticContent(Transport *transport, const char *data, int len,
65-
time_t mtime, bool compressed,
65+
time_t mtime,
6666
const std::string &cmd,
6767
const char *ext);
6868
bool executePHPRequest(Transport *transport, RequestURI &reqURI);

0 commit comments

Comments
 (0)