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

htp: fix case of nested FormField if first formField usage is with single parameter #2524

Merged
merged 4 commits into from
Jul 2, 2019

Conversation

jrudolph
Copy link
Member

@jrudolph jrudolph commented May 9, 2019

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.

@akka-ci akka-ci added validating PR that is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed validating PR that is currently being validated by Jenkins labels May 9, 2019
@akka-ci
Copy link

akka-ci commented May 9, 2019

Test FAILed.

@jrudolph jrudolph force-pushed the jr/form-field-improvements branch from d7f13e7 to 2128c61 Compare May 9, 2019 11:10
@akka-ci akka-ci added validating PR that is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR that is currently being validated by Jenkins labels May 9, 2019
@akka-ci
Copy link

akka-ci commented May 9, 2019

Test FAILed.

@jrudolph jrudolph force-pushed the jr/form-field-improvements branch from 2128c61 to 8d54a25 Compare May 9, 2019 12:01
@akka-ci akka-ci added validating PR that is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) validating PR that is currently being validated by Jenkins labels May 9, 2019
@akka-ci
Copy link

akka-ci commented May 9, 2019

Test PASSed.

@akka-ci akka-ci added validating PR that is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed tested PR that was successfully built and tested by Jenkins validating PR that is currently being validated by Jenkins labels May 17, 2019
@akka-ci
Copy link

akka-ci commented May 17, 2019

Test PASSed.

@johanandren
Copy link
Member

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 ?

Copy link
Member Author

@jrudolph jrudolph left a 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() }
Copy link
Member Author

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), _))
Copy link
Member Author

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.

Copy link
Member Author

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]
Copy link
Member Author

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.

Copy link
Member

@johanandren johanandren left a 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

Copy link
Member

@raboof raboof left a 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

@raboof
Copy link
Member

raboof commented May 27, 2019

MiMa:

[error]  * method formFields(akka.http.scaladsl.server.directives.FormFieldDirectives#FieldMagnet)java.lang.Object in trait akka.http.scaladsl.server.directives.FormFieldDirectives does not have a correspondent in current version
[error]    filter with: ProblemFilters.exclude[DirectMissingMethodProblem]("akka.http.scaladsl.server.directives.FormFieldDirectives.formFields")
[error]  * method formField(akka.http.scaladsl.server.directives.FormFieldDirectives#FieldMagnet)java.lang.Object in trait akka.http.scaladsl.server.directives.FormFieldDirectives does not have a correspondent in current version
[error]    filter with: ProblemFilters.exclude[DirectMissingMethodProblem]("akka.http.scaladsl.server.directives.FormFieldDirectives.formField")
[error]  * method formFields(akka.http.scaladsl.server.directives.FormFieldDirectives#FieldMagnet)akka.http.scaladsl.server.Directive in trait akka.http.scaladsl.server.directives.FormFieldDirectives is present only in current version
[error]    filter with: ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.http.scaladsl.server.directives.FormFieldDirectives.formFields")
[error]  * method formField(akka.http.scaladsl.server.directives.FormFieldDirectives#FieldMagnet)akka.http.scaladsl.server.Directive in trait akka.http.scaladsl.server.directives.FormFieldDirectives is present only in current version
[error]    filter with: ProblemFilters.exclude[ReversedMissingMethodProblem]

@jrudolph jrudolph force-pushed the jr/form-field-improvements branch from a92c758 to dbfdcb3 Compare June 6, 2019 15:02
@akka-ci akka-ci added validating PR that is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed tested PR that was successfully built and tested by Jenkins labels Jun 6, 2019
@raboof
Copy link
Member

raboof commented Jun 17, 2019

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?

@jrudolph jrudolph force-pushed the jr/form-field-improvements branch from ca39a59 to 6c6f668 Compare July 2, 2019 12:09
@akka-ci akka-ci added validating PR that is currently being validated by Jenkins needs-attention Indicates a PR validation failure (set by CI infrastructure) and removed tested PR that was successfully built and tested by Jenkins validating PR that is currently being validated by Jenkins labels Jul 2, 2019
@akka-ci
Copy link

akka-ci commented Jul 2, 2019

Test FAILed.

@jrudolph jrudolph force-pushed the jr/form-field-improvements branch from 6c6f668 to 9acf0e6 Compare July 2, 2019 12:20
@akka-ci akka-ci added validating PR that is currently being validated by Jenkins and removed needs-attention Indicates a PR validation failure (set by CI infrastructure) labels Jul 2, 2019
@jrudolph jrudolph force-pushed the jr/form-field-improvements branch from 9acf0e6 to 50f4e11 Compare July 2, 2019 12:26
@jrudolph jrudolph force-pushed the jr/form-field-improvements branch from 50f4e11 to 0528e5e Compare July 2, 2019 12:27
@jrudolph
Copy link
Member Author

jrudolph commented Jul 2, 2019

I think I fixed the incompatibility now. The idea was to keep the Out type member alongside the new U type member. This way the erased result type is still AnyRef. I added different alternative using @pre213 and @since213 so that we can drop the extra structure once 2.12 support is gone.

@akka-ci akka-ci added tested PR that was successfully built and tested by Jenkins and removed validating PR that is currently being validated by Jenkins labels Jul 2, 2019
@akka-ci
Copy link

akka-ci commented Jul 2, 2019

Test PASSed.

@akka-ci akka-ci added validating PR that is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed tested PR that was successfully built and tested by Jenkins validating PR that is currently being validated by Jenkins labels Jul 2, 2019
@akka-ci
Copy link

akka-ci commented Jul 2, 2019

Test PASSed.

@raboof raboof merged commit 1df739a into akka:master Jul 2, 2019
@raboof raboof added this to the 10.1.9 milestone Jul 2, 2019
@jrudolph jrudolph deleted the jr/form-field-improvements branch July 3, 2019 08:27
@raboof raboof mentioned this pull request Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tested PR that was successfully built and tested by Jenkins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants