Skip to content
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

Merged
merged 3 commits into from Dec 10, 2020
Merged

Replace Accept-Ranges parser with cats-parse implementation #3995

merged 3 commits into from Dec 10, 2020

Conversation

fredshonorio
Copy link
Contributor

This is a preliminary PR to request feedback, it does not fully replace RangeParser yet.

I added the cats-parse implementation to the Accept-Ranges companion object and I'd like some general feedback on my usage of cats-parse and any formatting/style stuff.

I also have a question about the previous implementation, (here) the top level rule for Accept-Ranges is matching on EOL but this caused the cats-parse version to fail tests, I assume that parboiled2 is different from cats-effect and this is not necessary but I want to confirm this.

@fredshonorio fredshonorio mentioned this pull request Dec 8, 2020
34 tasks
Copy link
Member

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

This is a great start. Replace the repSep, but I think you're on the right track here.


/* https://tools.ietf.org/html/rfc7233#appendix-C */
val parser: P[`Accept-Ranges`] = {
val ListSep: P[Unit] = Rfc7230.ows *> P.char(',') *> Rfc7230.ows
Copy link
Member

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.

val parser: P[`Accept-Ranges`] = {
val ListSep: P[Unit] = Rfc7230.ows *> P.char(',') *> Rfc7230.ows

val none = P.string1("none").as(Nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of as.

)
)

acceptableRanges.map(headers.`Accept-Ranges`.apply) /* is EOL necessary? */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct. Calling parseAll means Accept-Ranges.parse will have to consume the entire input, and if this is composed into other parsers, we want it to leave the leftovers.

@fredshonorio
Copy link
Contributor Author

Last commit should implement requested changes.

Copy link
Member

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a slight tweak to the error message, but this look great. Thanks!

@rossabaker rossabaker merged commit 159c63e into http4s:dotty Dec 10, 2020
@rossabaker rossabaker added this to In progress in Dotty cross-compilation via automation Dec 10, 2020
@rossabaker rossabaker moved this from In progress to Done in Dotty cross-compilation Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants