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
Models 'Forwarded' header #3609
Conversation
Great stuff. =) This should probably be targeted 0.21 ? |
I guess it could... Would you suggest to rebase it onto |
@satorg Yes |
8a14f7e
to
070d342
Compare
We should have some tests for this, I do believe there are some examples in the RFC |
Yes, for sure. I am working on the tests now, per se. |
8f89055
to
d70e3b5
Compare
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.
I was surprised how complicated this is, until I read the spec. This is really nice work.
} | ||
} | ||
|
||
final case class Obfuscated(value: String) extends AnyVal with Name with Port |
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.
Reading the spec, I expected obfnode
to be in Node
and obfport
to be in Port
. The grammar is the same for this type, but it seems weird to me for the type to do double duty.
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.
I agree that it is a controversial approach. I was just thinking – what would be advantages of making them separated?
I mean it would not only require to create two different (although identical) case classes here, but also two parser rules for creating these classes. No doubt we could share some of their implementation, but it would increase overall code complexity anyway (remember, there still should be fromString
as well as rendering implemented for both of them). On the other side, I couldn't come up with some real disadvantages besides, yeah, some weirdness.
I'm just trying to come up with some compromise solution that would let us avoid code duplication, preserve type safety and keep code complexity on some maintainable level. WDYT?
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 comment is about minutiae, so I don't feel too strongly.
Obfuscated
isn't as untyped as String
, but it still raises the question, "an obfuscated what?" It's not a particularly meaningful type on its own. Sharing makes the implementation more concise, but isn't semantically meaningful in an HTTP sense.
In the unlikely event that the next version of that RFC allows some other character in an obfuscated host, we've got room to change it. If the two unrelated concepts share a type, we'd have to wait for the next breaking release to implement it.
I don't think either argument matters much in this corner case of a supplemental RFC. I'm thinking more in general design. And you're right that the repetition is annoying, so I'm content either way.
Yeah, I also didn't realize that until I dove into this task. Unfortunately, due to my personal circumstances, I just didn't have enough time to squeeze it into 0.21.7, I am sorry for that. |
No apologies required at all. Glad for the help, and we won't run out of patch numbers any time soon. |
d70e3b5
to
5827307
Compare
f083958
to
1bfadcd
Compare
1bfadcd
to
5a91de6
Compare
Are we waiting on anything before this leaves draft status? |
Yeah... Two things actually:
Sorry, I totally realize that I'm holding this PR, but I haven't given up on it – just cannot set aside too much time for this job now. |
No worries. We should be getting ready for an 0.21.8 imminently, but this can always be in the next patch. |
518d33c
to
821e02c
Compare
Ok, it seems I'm getting close. I have implemented the model renderers and mostly need to add some tests for them. |
Looks like the last test failures are due to #3664... |
@jyoo980 no worries, I'm still working on my tests here anyway. |
cdc98c1
to
3e1a634
Compare
I believe I'm pretty much done with this PR. cc @rossabaker, @hamnis |
import org.http4s.{ParseResult, Uri} | ||
import org.scalacheck.{Arbitrary, Gen} | ||
|
||
private[http4s] trait ForwardedArbitraryInstances |
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.
I wonder, should this trait be moved to org.http4s.laws.discipline
(where ArbitraryInstances
sits)?
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.
I think yes, but that doesn't need to block this.
A colleage of mine just hit this in production scala/bug#8831 |
@hamnis, interesting issue, never seen it before. Thanks for pointing this out to me! I'd guess it's unlikely to affect this code since the bug usually appears when there are some common prefixes among parameters. But to be on the safer side, I agree, we can consider getting rid of backticks. As I wrote some time before, the backticks are only necessary for the But it is not the only option – we could rename all the parameters somehow else. For example, since all the parameters are actually optional, they could be renamed to sealed trait Element extends Renderable { _: Product =>
def maybeBy: Option[Node]
def maybeFor: Option[Node]
def maybeHost: Option[Host]
def maybeProto: Option[Proto]
...
} ..or something like that. WDYT? |
I've never been a fan of the backticks of for instance header classes just to get the "correct" name, it makes them less discoverable by for instance IDEA. So I prefer the latter version here. Other maintainers may prefer differently. @rossabaker any guidelines here? |
3e1a634
to
5fd4449
Compare
5fd4449
to
4c3c582
Compare
Looks like the most recent scalafmt has broken this PR. I'll take care of it. @rossabaker, btw, I'd appreciate your thoughts regarding the questions above. Feel free to make any suggestions please – I'm open to polish the PR as much as possible. |
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.
Thanks for your patience while I dig out of my hole. This is great work, and everything I mentioned is pretty insignificant.
import org.http4s.{ParseResult, Uri} | ||
import org.scalacheck.{Arbitrary, Gen} | ||
|
||
private[http4s] trait ForwardedArbitraryInstances |
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.
I think yes, but that doesn't need to block this.
fbe5d26
to
df320a2
Compare
df320a2
to
a160802
Compare
@rossabaker @hamnis I have worked through most of your comments, feel free to review the changes once again :) Moreover, I voluntarily decided to get rid of backticks in Also please feel free to make any further suggestions, if any. There's no rush on my side, I don't mind to continue polishing if necessary. |
Resolves #3471.
The
Forwarded
header model tries to be as type safe as possible and thus introduces a hierarchy of model classes for that.In particular,
Element
enables the following syntax for building elements: