Skip to content

Commit

Permalink
Add Body() parser (#205)
Browse files Browse the repository at this point in the history
* Add `Body()` parser

* wip

* wip
  • Loading branch information
stephencelis authored Apr 25, 2022
1 parent df6a89a commit 28d32e9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Sources/_URLRouting/Body.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public struct Body<Bytes: Parser>: Parser where Bytes.Input == Data {
/// var message: String
/// }
///
/// Body(.data.json(Comment.self))
/// Body(.json(Comment.self))
/// ```
///
/// - Parameter bytesConversion: A conversion that transforms bytes into some other type.
Expand All @@ -30,6 +30,12 @@ public struct Body<Bytes: Parser>: Parser where Bytes.Input == Data {
self.bytesParser = Rest().replaceError(with: .init()).map(bytesConversion)
}

/// Initializes a body parser that parses the body as data in its entirety.
@inlinable
public init() where Bytes == Parsers.ReplaceError<Rest<Bytes.Input>> {
self.bytesParser = Rest().replaceError(with: .init())
}

@inlinable
public func parse(_ input: inout URLRequestData) throws -> Bytes.Output {
guard var body = input.body
Expand Down

0 comments on commit 28d32e9

Please sign in to comment.