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

allow for empty request bodies to skip validation, fixes #1939 #1990

Merged
merged 1 commit into from
Feb 17, 2022

Conversation

daniel-white
Copy link

Addresses #1939

Summary

inspects the request content-length header for making the decision to enforce the content-type on the request. if it is >1 then the content-type header must be one of the request body types.

Checklist

  • The basics
    • I tested these changes manually in my local or dev environment
  • Tests
    • Added or updated
    • N/A
  • Event Tracking
    • I added event tracking and followed the event tracking guidelines
    • N/A
  • Error Reporting
    • I reported errors and followed the error reporting guidelines
    • N/A

@daniel-white daniel-white requested a review from a team as a code owner February 16, 2022 18:09
@daniel-white daniel-white requested review from chohmann and removed request for a team February 16, 2022 18:09
@@ -0,0 +1,26 @@
====test====
Given form data expected in request body
Copy link
Author

Choose a reason for hiding this comment

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

guess i should update these

@daniel-white daniel-white force-pushed the feat/allow-empty-body-ct branch from 7db1716 to 0e36fcc Compare February 16, 2022 18:24
return E.right(body);
}

const mediaType = headersNormalized.get('content-type');
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that I've seen how you did this, I like that it's inside validateInputIfBodySpecIsProvided().

Copy link
Contributor

Choose a reason for hiding this comment

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

samesies! 🙌 Nice work!

return E.right(body);
}

const mediaType = headersNormalized.get('content-type');
Copy link
Contributor

Choose a reason for hiding this comment

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

samesies! 🙌 Nice work!

@rngtng
Copy link

rngtng commented Apr 14, 2023

thanks for the fix. Could it be that with this an empty PSOT request body doesn't trigger exception when a body payload is required? In my case I somehow can't get an exception triggered on missing body...!?

I quick drafted a potential test case here:

====test====
Given a request declaring a content-type but has no body although it is required
then return 400
====spec====
openapi: '3.1.0'
paths:
  /path:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - foo
               properties:
                 foo:
                   type: string
      responses:
        200:
          content:
            text/plain:
              example: ok
       400:
          content:
            text/plain:
              example: body required
====server====
mock -p 4010 ${document}
====command====
curl -i -X POST http://localhost:4010/path -H "Content-Type: application/json"
====expect====
HTTP/1.1 400 Bad Request
content-type: text/plain

body required

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.

4 participants