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

Simple change to remove hop-by-hop headers when relaying respon… #921

Merged

Conversation

rogersolsvik
Copy link
Contributor

…se from upstream

Checklist

  • Tests have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce?

Bug fix

What is the current behavior? What is the new behavior?

When running prism proxy it relays all headers from upstream source, even after adding new ones that might be incompatible with the original response.

More specifically in my case, my application is sending the Transfer-Encoding: chunked header, but since Prism is buffering the whole response to do response validation, is also adds the Content-Length header. These headers are incompatible and causes certain clients to fail. For example, Postman fails with a «Parse error» without a decent cause description.

Read more about the Transfer-Encoding header here

Does this PR introduce a breaking change?

Should be no breaking changes with this PR as far as I can see

@XVincentX
Copy link
Contributor

Oh ok — interesting issue. The fix seems legit, however I would like to check it out deeply before I can merge and release this.

Thanks for the good investigation!

@rogersolsvik
Copy link
Contributor Author

No problem @XVincentX. It might be appropriate make this fix for other "hop-by-hop" headers as well, but did not investigate which other might cause an issue too.
Other "hop-by-hop" headers are:

Connection
Keep-Alive
Public
Proxy-Authenticate
Transfer-Encoding
Upgrade

@XVincentX
Copy link
Contributor

Yeah that is exactly my point — more investigation might be required to make this work properly in all the circumstances.

@rogersolsvik
Copy link
Contributor Author

Good. Let me know if I can help. I you want to remove all hop-by-hop headers as a part of this pull request, I can make the appropriate updates.

Copy link
Contributor

@XVincentX XVincentX left a comment

Choose a reason for hiding this comment

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

Ok I've read a little bit around and yes, we should be removing these headers in case

  1. The http-server is in Proxy mode
  2. The hop-by-hop header is not being returned as part of the mocked response

Would you be willing to complete the PR with such changes and add the relative tests @rogersolsvik

packages/http-server/src/server.ts Outdated Show resolved Hide resolved
@rogersolsvik rogersolsvik force-pushed the fix/transfer-encoding-header branch 2 times, most recently from 2daad7c to 90ad5e4 Compare January 12, 2020 11:07
@rogersolsvik
Copy link
Contributor Author

A little premature push. Will be fixing test soon

…in the forwarder. This also to ensure these headers are only removed when proxying. Added test to verify.
@rogersolsvik rogersolsvik changed the title Simple change to remove transfer-encoding header when relaying respon… Simple change to remove hop-by-hop headers when relaying respon… Jan 12, 2020
@rogersolsvik
Copy link
Contributor Author

I have not setup the harness tests locally. Any input on what's going wrong @XVincentX ?

@rogersolsvik
Copy link
Contributor Author

Did an update from master now which triggered a rebuild. The harness tests seem to work now.

@XVincentX
Copy link
Contributor

Thanks for checking this out — Ill review.

Copy link
Contributor

@XVincentX XVincentX left a comment

Choose a reason for hiding this comment

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

Some comments — check them out if you have time or I can make it over the finish line

packages/http/src/forwarder/__tests__/index.spec.ts Outdated Show resolved Hide resolved
packages/http/src/forwarder/index.ts Outdated Show resolved Hide resolved
packages/http/src/forwarder/index.ts Outdated Show resolved Hide resolved
@XVincentX
Copy link
Contributor

@rogersolsvik Thanks for the follow up. I'll check it out again but I think this might be good to merge now. Thanks!

@XVincentX
Copy link
Contributor

Thanks, @rogersolsvik

@XVincentX XVincentX merged commit c0b768e into stoplightio:master Jan 20, 2020
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.

None yet

2 participants