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
Replace Accept-Ranges
parser with cats-parse implementation
#3995
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,9 @@ | |
|
||
package org.http4s | ||
package headers | ||
|
||
import org.http4s.parser.HttpHeaderParser | ||
import cats.parse.{Parser => P} | ||
import cats.implicits._ | ||
import org.http4s.internal.parsing.Rfc7230 | ||
import org.http4s.util.Writer | ||
|
||
object `Accept-Ranges` extends HeaderKey.Internal[`Accept-Ranges`] with HeaderKey.Singleton { | ||
|
@@ -16,7 +17,33 @@ object `Accept-Ranges` extends HeaderKey.Internal[`Accept-Ranges`] with HeaderKe | |
def none: `Accept-Ranges` = apply(Nil) | ||
|
||
override def parse(s: String): ParseResult[`Accept-Ranges`] = | ||
HttpHeaderParser.ACCEPT_RANGES(s) | ||
parser.parseAll(s).leftMap { e => | ||
ParseFailure("Invalid accept-ranges", e.toString) | ||
} | ||
|
||
/* https://tools.ietf.org/html/rfc7233#appendix-C */ | ||
val parser: P[`Accept-Ranges`] = { | ||
val ListSep: P[Unit] = Rfc7230.ows *> P.char(',') *> Rfc7230.ows | ||
|
||
val none = P.string1("none").as(Nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of |
||
|
||
val rangeUnit = Rfc7230.token.map(org.http4s.RangeUnit.apply) | ||
|
||
/* | ||
Accept-Ranges = acceptable-ranges | ||
OWS = <OWS, see [RFC7230], Section 3.2.3> | ||
acceptable-ranges = ( *( "," OWS ) range-unit *( OWS "," [ OWS range-unit ] ) ) / "none" | ||
*/ | ||
val acceptableRanges: P[List[RangeUnit]] = | ||
P.oneOf( | ||
List( | ||
none, | ||
P.repSep(rangeUnit, 1, ListSep) | ||
) | ||
) | ||
|
||
acceptableRanges.map(headers.`Accept-Ranges`.apply) /* is EOL necessary? */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is correct. Calling |
||
} | ||
} | ||
|
||
final case class `Accept-Ranges` private[http4s] (rangeUnits: List[RangeUnit]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will do a fine job on the ows-comma-ows that reasonable actors will send, but not the empty elements between commas (including leading and trailing commas) that the spec mandates.
Rfc7230.headerRep1
should take care of those.