-
Notifications
You must be signed in to change notification settings - Fork 594
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
htp: fix case of nested FormField if first formField usage is with single parameter #2524
Conversation
Test FAILed. |
d7f13e7
to
2128c61
Compare
Test FAILed. |
2128c61
to
8d54a25
Compare
Test PASSed. |
Test PASSed. |
Tried to review this and looked at the previous PR but I don't understand how it works, could you give a brief explanation @jrudolph ? |
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.
See the comments below.
There is also an alternative one line change (with cheats):
toStrictEntity(...).wrap { pdm().asInstanceOf[Directive[_]] }.asInstanceOf[pdm.Out]
but would we like that?
|
||
/** | ||
* Extracts a number of HTTP form field from the request. | ||
* Rejects the request if the defined form field matcher(s) don't match. | ||
* | ||
* @group form | ||
*/ | ||
def formFields(pdm: FieldMagnet): pdm.Out = pdm() | ||
override def formFields(pdm: FieldMagnet): Directive[pdm.U] = | ||
toStrictEntity(StrictForm.toStrictTimeout).wrap { pdm() } |
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.
That's basically the fix. We want to be sure that the complete inner part of a formField directive is wrapped in a toStrictEntity
directive.
The problem in the old version was, that we couldn't prove that pdm()
actually is a directive, so we couldn't use wrap
.
|
||
//////////////////// tuple support //////////////////// | ||
|
||
import akka.http.scaladsl.server.util.BinaryPolyFunc | ||
import akka.http.scaladsl.server.util.TupleOps._ | ||
|
||
implicit def forTuple[T](implicit fold: FoldLeft[Directive0, T, ConvertFieldDefAndConcatenate.type]): FieldDefAux[T, fold.Out] = | ||
fieldDef[T, fold.Out](fold(toStrictEntity(StrictForm.toStrictTimeout), _)) |
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.
That's the old fix which fixed it for formField('a, 'b)
, i.e. if there are more than two form fields, than fold the directives starting with toStrictEntity
on the outside.
It didn't fix it for the other cases of a single form field, though. One potential solution would be to add toStrictEntity
to all the implicits for the single form field above, that would work but would mean that we would add toStrictEntity
as many times as we have formFields
which would add a bit of overhead.
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.
Thinking about it, there's already existing overhead: for every given field, we run the complete unmarshalling which seems wasteful. So, that could be another area of improvement.
type Out | ||
def apply(): Out | ||
type U | ||
def apply(): Directive[U] |
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.
So, the typesafe fix is to add enough types here (and everywhere) to declare that the result of pdf()
above actually is a Directive
and not just anything.
That is we add the Directive
type here and remove the Directive
wrapping in all types below. Note that type Directive1[T] = Directive[Tuple1[T]]
etc.
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 the explanation!
LGTM
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.
Nice to be more explicit about those types anyway
there are some ⇒
utf8 characters that snuck in there
MiMa:
|
a92c758
to
dbfdcb3
Compare
Hmm tricky. Perhaps we should start planning dropping support for 2.11 (some time after Akka 2.6 is released?) and postponing this PR until then? |
ca39a59
to
6c6f668
Compare
Test FAILed. |
Somehow it was missed when the scalariform version was updated
6c6f668
to
9acf0e6
Compare
9acf0e6
to
50f4e11
Compare
50f4e11
to
0528e5e
Compare
I think I fixed the incompatibility now. The idea was to keep the |
Test PASSed. |
Test PASSed. |
So far, in #2283 the case for tuples was fixed which also worked for nested
formField
directives in most of the cases but not when the first usage was with a single argument.Refs #73.