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

migrate multiple simple header parser #4154

Merged
merged 3 commits into from Jan 9, 2021

Conversation

m-sp
Copy link
Member

@m-sp m-sp commented Jan 7, 2021

migrates

  • Age
  • Connection
  • Content-Length
  • Strict-Transport-Security

@m-sp m-sp changed the base branch from main to series/0.22 January 7, 2021 16:17
@m-sp
Copy link
Member Author

m-sp commented Jan 7, 2021

hmm seems the tests failed, I'll take a look

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!

ParseResult.fromParser(parser, "Invalid Connection header")(s)

private[http4s] val parser =
Parser.rep1Sep(Rfc2616.token, 1, Rfc2616BasicRules.listSep).map { (xs: NonEmptyList[String]) =>
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 should be the headerRep1 helper.

@@ -213,4 +214,11 @@ private[http4s] object AdditionalRules {
def EOI = P.char('\uFFFF')

def EOL = optWs *> EOI.rep

val Digits: Parser1[Long] = P.rep1(Rfc3986.digit, 1).string.mapFilter { s =>
Copy link
Member

Choose a reason for hiding this comment

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

There's a digit in cats.parse.Rfc5234 that we can use. I guess the value in having a separate rule is that yours does the work of parsing a run of them to a long, while the cats-parse one just gives you the Char.

I think I'd call this Long, to show that arbitrary lengths will fail. Or maybe even NonNegativeLong, because a leading minus won't work here. I do think it's useful.


private[http4s] val parser: Parser[`Strict-Transport-Security`] = {
val maxAge: Parser1[`Strict-Transport-Security`] =
(Parser.string1("max-age=") *> AdditionalRules.Digits).map { (age: Long) =>
Copy link
Member

Choose a reason for hiding this comment

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

Is this case sensitive? I bet it's not, but I'd have to find the RFC.

Copy link
Member Author

Choose a reason for hiding this comment

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

https://tools.ietf.org/html/rfc6797#section-6.1

Directive names are case-insensitive.

thanks you are right, will change

@m-sp m-sp requested a review from rossabaker January 8, 2021 23:19
@rossabaker rossabaker merged commit 04b43d6 into http4s:series/0.22 Jan 9, 2021
@m-sp m-sp deleted the port-simple-headers branch January 9, 2021 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants