When sending a request body that decodes a Content type. If the request is sent as multipart with the right header set, but the body is empty, a 500 error is returned. This can cause problems with apps that have automatic reporting for internal server errors as it should be reported as a bad request
The text was updated successfully, but these errors were encountered:
@0xTim@BennyDeBock, Is this still an issue? Was looking into it but it seems like it was resolved.
The private _ContentContainer struct for a Request object has its decode method throw Abort(.unprocessableEntity) when body is nil. Line 76 inside Request.swift.
Here's a snippet of the decode method I'm referencing:
func decode<D>(_ decodable: D.Type, using decoder: ContentDecoder) throws -> D where D : Decodable {
guard let body = self.request.body.data else {
self.request.logger.debug("Request body is empty. If you're trying to stream the body, decoding streaming bodies not supported")
throw Abort(.unprocessableEntity)
}
return try decoder.decode(D.self, from: body, headers: self.request.headers)
}
paunik
pushed a commit
to paunik/vapor
that referenced
this issue
May 23, 2022
@jareyesda I have opened MR that covers that some while ago, now i have rebased and ran the tests, seems that issue is still present. If You can check, do I need to add some more things or we should close this MR.
Best
When sending a request body that decodes a
Contenttype. If the request is sent as multipart with the right header set, but the body is empty, a 500 error is returned. This can cause problems with apps that have automatic reporting for internal server errors as it should be reported as a bad requestThe text was updated successfully, but these errors were encountered: