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

Allowing body to be either string or stream #43

Closed
wants to merge 1 commit into from
Closed

Allowing body to be either string or stream #43

wants to merge 1 commit into from

Conversation

ska2342
Copy link

@ska2342 ska2342 commented Jul 26, 2016

When this middleware is used together with other middlewares
it may run into a conflict trying to slurp the body.
If the other middleware already slurped the body and put the
resulting string back into the request the slurp in this middleware
fails.
This commit adds handling of string-type body.

When this middleware is used together with other middlewares
it may run into a conflict trying to slurp the body.
If the other middleware already slurped the body and put the
resulting string back into the request the slurp in this middleware
fails.
This commit adds handling of string-type body.
@weavejester
Copy link
Member

weavejester commented Jul 27, 2016

The request body can only be an InputStream, otherwise it's not a valid Ring request.

Ideally other middleware shouldn't consume the body if they don't need to. Checking the content-type of the request is a good way to avoid consuming request bodies that you don't need to. If you absolutely cannot avoid consuming the body (even after checking the content type!) then replace the body with a ByteArrayInputStream.

@ska2342
Copy link
Author

ska2342 commented Jul 27, 2016

Oh, I wasn't aware that the body has to be an InputStream, probably I was so used to working with the Clojure hash-map, that the JSON middleware gives me.

I must consume all bytes of the body to validate it like this: https://developer.github.com/webhooks/securing/. Then I replaced the body like this:

(assoc request :body (io/input-stream (.getBytes body-string)))

but thought that'd be rather hackish. It seems that this is exactly what you suggest, so I am probably fine with it.
I think we can close this PR then.. Thanks.

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