-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Http compression config #50738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Http compression config #50738
Changes from all commits
00f23f5
cb4d41c
ca43241
f60d0b7
d5a5c19
d9a9774
ce72306
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| */ | ||
|
|
||
| import { Request, Server } from 'hapi'; | ||
| import url from 'url'; | ||
|
|
||
| import { Logger, LoggerFactory } from '../logging'; | ||
| import { HttpConfig } from './http_config'; | ||
|
|
@@ -96,6 +97,7 @@ export class HttpServer { | |
|
|
||
| const basePathService = new BasePath(config.basePath); | ||
| this.setupBasePathRewrite(config, basePathService); | ||
| this.setupConditionalCompression(config); | ||
|
|
||
| return { | ||
| registerRouter: this.registerRouter.bind(this), | ||
|
|
@@ -187,6 +189,33 @@ export class HttpServer { | |
| }); | ||
| } | ||
|
|
||
| private setupConditionalCompression(config: HttpConfig) { | ||
| if (this.server === undefined) { | ||
| throw new Error('Server is not created yet'); | ||
| } | ||
|
|
||
| const { enabled, referrerWhitelist: list } = config.compression; | ||
| if (!enabled) { | ||
| this.log.debug('HTTP compression is disabled'); | ||
| this.server.ext('onRequest', (request, h) => { | ||
| request.info.acceptEncoding = ''; | ||
| return h.continue; | ||
|
Comment on lines
+200
to
+202
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this quite brutal? I think this header can be used for other things than compression?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oups, this and accept are not the same header. |
||
| }); | ||
| } else if (list) { | ||
| this.log.debug(`HTTP compression is only enabled for any referrer in the following: ${list}`); | ||
| this.server.ext('onRequest', (request, h) => { | ||
| const { referrer } = request.info; | ||
| if (referrer !== '') { | ||
| const { hostname } = url.parse(referrer); | ||
| if (!hostname || !list.includes(hostname)) { | ||
| request.info.acceptEncoding = ''; | ||
| } | ||
| } | ||
| return h.continue; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| private registerOnPostAuth(fn: OnPostAuthHandler) { | ||
| if (this.server === undefined) { | ||
| throw new Error('Server is not created yet'); | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like an integration test and should be in
src/core/server/http/integration_testsinsteadThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I'll move it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline, looks like these tests / usage of supertest are in the correct place after all =)