Skip to content
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

Cleanup on headers handling #370

Merged
merged 3 commits into from
Jan 30, 2017
Merged

Cleanup on headers handling #370

merged 3 commits into from
Jan 30, 2017

Conversation

matteofigus
Copy link
Member

While cleaning up a bit the code (I wanted to remove the delete as it may be not great for v8's optimisation, I had the chance to look again at all the tests and I found a couple of things that I'd like to change.

  1. When doing the GET /component I think headers should be set as headers and not included in the response
  2. When doing the POST / for the batch endpoint I think headers should not be set but included in the response. Still, I moved them from being in the response.headers to just headers (one level down). I think this allows us to have "response" to be exactly identical as a GET /component response.

I would be tempted to publish this as a bugfix instead of breaking change if you agree @ivan-dimitrov-skyscanner

Also, we may need to revisit your PR #347 as I think if we have all the headers in the POST perhaps we don't need that?

More details inline.


if (req.method === 'GET') {
delete result.response.headers;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not actually needed as component.js is used only by the GET endpoint. Also delete can be not great for performances so I revert the strategy (to not set it in the response and then to make it part of the POST individual result)

@@ -167,7 +167,7 @@ describe('registry', function(){
it('should return the component with custom headers', function() {
expect(result[0].response.version).to.equal('1.0.0');
expect(result[0].response.name).to.equal('hello-world-custom-headers');
expect(result[0].response.headers).to.be.deep.equal({'cache-control': 'public max-age=3600', 'test-header': 'Test-Value'});
expect(result[0].headers).to.be.deep.equal({'cache-control': 'public max-age=3600', 'test-header': 'Test-Value'});
Copy link
Member Author

Choose a reason for hiding this comment

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

I actually think I didn't pay so much attention on the previous review as I was surprised to see this. What do you think @ivan-dimitrov-skyscanner ? Can we safely change this and consider it as a bugfix?

Copy link
Contributor

Choose a reason for hiding this comment

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

@matteofigus It seems as a kind of invariant to me. However I tried to checkout your changes locally and play it them and for some reason I could not see how to do it :-(
And the main thing we'd liked to accomplish was:

  • in case of GET the headers should be visible as normal HTTP response headers
  • in case of POST they should not be set as HTTP response headers (because there is no point to do it) but to be present in the normal response body.
    And from this point of view your change looks OK to me.

Copy link
Member Author

@matteofigus matteofigus Jan 29, 2017

Choose a reason for hiding this comment

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

Yeah agree. I think the purposed change here is to move headers one level down on the POST so that instead of having

{   
  components: [{
    status: 200,
    response: {
      ...
      headers: { ... }
    }
  }]
}

we have

{   
  components: [{
    status: 200,
    response: {
      ...
    },
    headers: { ... }
  }]
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, and also I'm OK to have it as a bugfix instead of a breaking change :-)

@@ -453,8 +453,7 @@ describe('registry : routes : component', function(){
});

it('should set response headers', function() {
expect(response.headers).to.not.be.null;
expect(response.headers['test-header']).to.equal('test-value');
expect(response.headers).to.be.undefined;
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this tests were actually broken. The GET shouldn't have headers inside the response so this fixes it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @matteofigus, thanks for getting back. Can you give me one more day to revisit it as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

No problem take your time ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right - those tests were broken :-(

@i-b-dimitrov
Copy link
Contributor

@matteofigus,
Regarding PR #347 - I think we'll still need it because even though we'll have all the headers in the POST, the majority of the HTTP proxies (CDN, etc.) which stay on the request-response path don't cache responses of POST requests. For this reason I think we still need a GET request when dealing with just single component.

@matteofigus
Copy link
Member Author

Thanks, so let me merge this and then we'll review that one ;)

@matteofigus matteofigus merged commit eebeb49 into master Jan 30, 2017
@matteofigus matteofigus deleted the delete branch January 30, 2017 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants