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

don't strip request body if we don't recognize the request method #294

Merged
merged 2 commits into from
Jul 3, 2019
Merged

don't strip request body if we don't recognize the request method #294

merged 2 commits into from
Jul 3, 2019

Conversation

eli-darkly
Copy link
Collaborator

This addresses #290 by changing the request-processing behavior from this--

  • Is the request method is one of the specific methods that we know can have a body?
  • If so, then preserve the request body.
  • Otherwise, discard the request body.

--to this:

  • Is the request method is one of the specific methods that we know cannot have a body?
  • If so, then discard the request body.
  • Otherwise, preserve the request body.

For any of the methods that were already listed in BodyParser.cs, this change has no effect: request bodies will still be discarded for GET or DELETE, preserved for POST or PUT, etc. But for methods that were not specifically mentioned there (like REPORT), the request body (if any) will be preserved. I believe this is more in line with the HTTP specification, which only says that a server should discard the body if the method is known not to allow one.

While REPORT was the method I wanted to use in my own code, I didn't bother adding it to this list because it's just one of many rarely-used methods that appear in the HTTP Method Registry.

@codecov
Copy link

codecov bot commented Jun 28, 2019

Codecov Report

Merging #294 into master will increase coverage by 0.03%.
The diff coverage is 89.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #294      +/-   ##
==========================================
+ Coverage   79.72%   79.75%   +0.03%     
==========================================
  Files         108      108              
  Lines        4305     4322      +17     
==========================================
+ Hits         3432     3447      +15     
- Misses        873      875       +2
Impacted Files Coverage Δ
src/WireMock.Net/Util/BodyParser.cs 90.9% <89.47%> (-0.56%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0ce26ab...06a7395. Read the comment docs.

Copy link
Collaborator

@StefH StefH left a comment

Choose a reason for hiding this comment

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

Maybe instead of

if (method == null)

Use string.isnullorempty

@StefH StefH merged commit 06576ab into WireMock-Net:master Jul 3, 2019
@eli-darkly eli-darkly deleted the AllowBodyForUnknownMethods branch July 3, 2019 16:42
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