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

Add Content-Length checking before decoding #63

Merged

Conversation

perigrin
Copy link
Contributor

@perigrin perigrin commented Oct 5, 2020

We have a pattern with REST APIs at work where they return a 201 with a Location header for the new resource and an empty response body. Sling would attempt to decode the empty response body and return an EOF error.

  • Add a check before attempting to decode the response body to make sure that it's a non-zero Content-Length.
  • Update the tests to check that this specific case works
  • Update the GoDoc and comments

perigrin and others added 2 commits October 5, 2020 11:52
In addition to explicit 204 (NO CONTENT), there are occasions where the
server may send a 0 length response and those won't decode very well
either.
@dghubble dghubble merged commit cb0cde7 into dghubble:master Oct 29, 2020
@dghubble
Copy link
Owner

Thanks

// If the status code of response is 204(no content), decoding is skipped.
// Any error creating the request, sending it, or decoding the response is
// returned.
// If the status code of response is 204(no content) or the Content-Lenght is 0,

Choose a reason for hiding this comment

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

In case it's helpful to you, please note there's a typo in "Content-Lenght". It should be "Content-Length".

@addeshmu
Copy link

addeshmu commented Aug 1, 2021

any plans to release this change @dghubble ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants