Skip to content

Conversation

@kobelb
Copy link
Contributor

@kobelb kobelb commented Oct 9, 2019

When there is a "referer", this disables response compression.

@kobelb kobelb requested a review from a team as a code owner October 9, 2019 19:33
throw new Error('Server is not created yet');
}

this.server.ext('onRequest', (request, h) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't able to use registerOnPreAuth here because it doesn't expose the info. I'm assuming this generally isn't something we want to support, so I'm using the HapiJS interfaces directly. If you all think we should modify the KibanaRequest to include this, just let me know.

registerRouter(router);

await server.start();
const response = await innerServer.inject({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to use .inject here, as opposed to how the other tests are using supertest with the listener or else I wasn't able to use response.request.info. I also wasn't able to look at response.headers['content-encoding'] because this isn't being set by Hapi...

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel great about testing implementation details rather than the actual HTTP response. It looks like supertest allows setting headers with the set method. Is it overriding it? If so, could we use a different way of sending a request in this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't either... Even if I set the request headers, the response coming back from HapiJS doesn't have the Content-Encoding header set, even though it ends up having it in the functional tests...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HapiJS seems to be skipping the actual compression in this situation, and it's not immediately obvious why: https://github.com/elastic/kibana/pull/47751/files#diff-51730cbab06a430a940f78fc9e710bd7R620-R637

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, maybe not worth figuring out why since we do at least the functional test which covers the blackbox behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can look into it further to try to understand why. I gave up more easily than I usually do because.... hapi...

@kobelb kobelb added the release_note:skip Skip the PR/issue when compiling release notes label Oct 9, 2019
@elasticmachine
Copy link
Contributor

💔 Build Failed

registerRouter(router);

await server.start();
const response = await innerServer.inject({
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, maybe not worth figuring out why since we do at least the functional test which covers the blackbox behavior.


const router = new Router('', logger, enhanceWithContext);
router.get({ path: '/', validate: false }, (context, req, res) =>
res.ok({ body: 'hello', headers: { 'Content-Type': 'text/html; charset=UTF-8' } })
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe there is threshold 1kB to enable gzip. Should fix the problem:

body: 'hello'.repeat(500), 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Mikhail!

await supertest(innerServer.listener)
.get('/')
.set('accept-encoding', 'gzip')
.then(response => {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we avoid mixing async/await and promise syntax?

const response = await supertest(...);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's rather prevalent within this file, but sure!

Copy link
Contributor

@mshustov mshustov left a comment

Choose a reason for hiding this comment

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

Let's switch to http interface instead of using hapi specific API.

@kobelb
Copy link
Contributor Author

kobelb commented Oct 18, 2019

Let's switch to http interface instead of using hapi specific API.

To be able to use registerOnPreAuth, I'll have to modify KibanaRequest to be able to get request.info.referrer and set request.info.acceptEncoding. Unless there's an alternative approach that I haven't thought of. Is that acceptable?

@mshustov
Copy link
Contributor

mshustov commented Oct 18, 2019

@kobelb sorry, I mean for tests. implementation is ok

@elasticmachine
Copy link
Contributor

💔 Build Failed


const router = new Router('', logger, enhanceWithContext);
router.get({ path: '/', validate: false }, (context, req, res) =>
res.ok({ body: 'hello'.repeat(500), headers: { 'Content-Type': 'text/html; charset=UTF-8' } })
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we add a comment why we make such a long body?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, great idea. I will make it so.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@mshustov
Copy link
Contributor

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@kobelb kobelb merged commit 85e5885 into elastic:master Oct 21, 2019
@kobelb kobelb deleted the no-compression-with-referer branch October 21, 2019 13:35
@kobelb kobelb added the v7.6.0 label Oct 21, 2019
kobelb added a commit to kobelb/kibana that referenced this pull request Oct 21, 2019
* Hacking it in there, this is obviously not where this belongs

* Moving implementation to a private method

* Adding unit tests, I don't like the way I had to write these

* Adding integration tests

* Test not relying on implementation details...

* No longer using .inject, thanks Mikhail!!!

* Adding comment explaining the long body

* Fixing nesting of describes for api integration tests
kobelb added a commit to kobelb/kibana that referenced this pull request Oct 21, 2019
* Hacking it in there, this is obviously not where this belongs

* Moving implementation to a private method

* Adding unit tests, I don't like the way I had to write these

* Adding integration tests

* Test not relying on implementation details...

* No longer using .inject, thanks Mikhail!!!

* Adding comment explaining the long body

* Fixing nesting of describes for api integration tests
kobelb added a commit that referenced this pull request Oct 21, 2019
* Hacking it in there, this is obviously not where this belongs

* Moving implementation to a private method

* Adding unit tests, I don't like the way I had to write these

* Adding integration tests

* Test not relying on implementation details...

* No longer using .inject, thanks Mikhail!!!

* Adding comment explaining the long body

* Fixing nesting of describes for api integration tests
kobelb added a commit that referenced this pull request Oct 21, 2019
* Hacking it in there, this is obviously not where this belongs

* Moving implementation to a private method

* Adding unit tests, I don't like the way I had to write these

* Adding integration tests

* Test not relying on implementation details...

* No longer using .inject, thanks Mikhail!!!

* Adding comment explaining the long body

* Fixing nesting of describes for api integration tests
kobelb added a commit to kobelb/kibana that referenced this pull request Nov 1, 2019
kobelb added a commit that referenced this pull request Nov 6, 2019
kobelb added a commit to kobelb/kibana that referenced this pull request Nov 6, 2019
kobelb added a commit that referenced this pull request Nov 7, 2019
kobelb added a commit that referenced this pull request Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:skip Skip the PR/issue when compiling release notes v7.5.0 v7.6.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants