Skip to content

Parsers set body even when they should not parse #269

@bricka

Description

@bricka

Hello! I just ran into a bug in another piece of software based on an interesting behavior in body-parser:
apigee-127/swagger-tools#533

The problem here is that even if a body parser should not parse (e.g. because the content type does not match), the parser still sets req.body = {}. This led another tool to think that parsing had already occurred, because req.body was defined.

I was wondering if it is possible to not modify the request at all if parsing should not be performed. That is the behavior I would expect.

You can see an example of this behavior in the raw parser here:

req.body = req.body || {}
// skip requests without bodies
if (!typeis.hasBody(req)) {
debug('skip empty body')
next()
return
}
debug('content-type %j', req.headers['content-type'])
// determine if request should be parsed
if (!shouldParse(req)) {
debug('skip parsing')
next()
return
}

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy