Skip to content

Instantly share code, notes, and snippets.

View zygoat's full-sized avatar

Ben Kennedy zygoat

View GitHub Profile
/// A middlware that filters a request body of type `application/x-www-form-urlencoded`
/// removing any key/value pairs having a zero-length value.
///
/// This is a remediation for a design defect where the presence of any such null entries
/// will cause model decoding to fail. See https://github.com/vapor/vapor/issues/3046.
struct URLEncodedFormSanitizingMiddlware: AsyncMiddleware {
func respond(to request: Request,
chainingTo next: AsyncResponder) async throws -> Response {
// Read the entire body content, which might not yet be available.
let bodyString: String?