Skip to content

Lazy header parse #4933

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

Merged
merged 1 commit into from
Jun 26, 2021
Merged

Conversation

RaasAhsan
Copy link

Ran into this when while trying to debug why a header parser was throwing an exception on a header it wasn't even intended for. The way it's coded right now, if we try to parse a header from its raw form, it'll parse every preceding header searched as well, even if the name doesn't match. This is definitely a performance hit when headers are queried

@RaasAhsan RaasAhsan added the bug Determined to be a bug in http4s label Jun 20, 2021
@RaasAhsan RaasAhsan requested a review from rossabaker June 20, 2021 07:56
@@ -182,7 +182,7 @@ object Header {
type Aux[A, G[_]] = Select[A] { type F[B] = G[B] }

def fromRaw[A](h: Header.Raw)(implicit ev: Header[A, _]): Option[Ior[ParseFailure, A]] =
(h.name == Header[A].name).guard[Option].as(Header[A].parse(h.value).toIor)
(h.name == Header[A].name).guard[Option].map(_ => Header[A].parse(h.value).toIor)
Copy link
Author

Choose a reason for hiding this comment

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

this was the quickest change, but i wouldn't be against rewriting this to be an if statement so the laziness is more apparent. or we can add a comment

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.

Eek. I think of these as interchangeable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Determined to be a bug in http4s module:core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants