Skip to content

Commit

Permalink
Fix binary incompatibility issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jrudolph committed Jul 2, 2019
1 parent f22774b commit 9acf0e6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
3 changes: 2 additions & 1 deletion akka-http/src/main/mima-filters/10.1.8.backwards.excludes
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.http.scaladsl.unmarsh
ProblemFilters.exclude[DirectAbstractMethodProblem]("akka.http.scaladsl.server.directives.FormFieldDirectivesCompat.formFields")
ProblemFilters.exclude[DirectAbstractMethodProblem]("akka.http.scaladsl.server.directives.FormFieldDirectivesCompat.formField")

# FieldMagnet / FieldDef should not be extended or called by third-part code.
# FieldMagnet / FieldDef should not be extended or called by third-party code.
ProblemFilters.exclude[IncompatibleResultTypeProblem]("akka.http.scaladsl.server.directives.FormFieldDirectives#FieldMagnet.apply")
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.http.scaladsl.server.directives.FormFieldDirectives#FieldMagnet.apply")
ProblemFilters.exclude[IncompatibleResultTypeProblem]("akka.http.scaladsl.server.directives.FormFieldDirectives#FieldDef.apply")
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.http.scaladsl.server.directives.FormFieldDirectives#FieldDef.apply")
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.http.scaladsl.server.directives.FormFieldDirectives#FieldMagnet.convert")
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package directives

import akka.annotation.DoNotInherit
import akka.annotation.InternalApi

import akka.http.impl.util._
import akka.http.scaladsl.common._
import akka.http.scaladsl.model.EntityStreamSizeException
Expand All @@ -20,12 +19,14 @@ import scala.collection.immutable
import scala.concurrent.Future
import scala.util.{ Failure, Success }
import BasicDirectives._
import akka.http.ccompat.pre213
import akka.http.ccompat.since213

/**
* @groupname form Form field directives
* @groupprio form 90
*/
trait FormFieldDirectives extends ToNameReceptacleEnhancements with FormFieldDirectivesCompat {
trait FormFieldDirectives extends ToNameReceptacleEnhancements {
import FormFieldDirectives._

/**
Expand Down Expand Up @@ -55,30 +56,37 @@ trait FormFieldDirectives extends ToNameReceptacleEnhancements with FormFieldDir
*
* @group form
*/
override def formField(pdm: FieldMagnet): Directive[pdm.U] = formFields(pdm)
@pre213
def formField(pdm: FieldMagnet): pdm.R = formFields(pdm)

/**
* Extracts an HTTP form field from the request.
* Rejects the request if the defined form field matcher(s) don't match.
*
* @group form
*/
@since213
def formField(pdm: FieldMagnet): Directive[pdm.U] = formFields(pdm)

/**
* 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
*/
override def formFields(pdm: FieldMagnet): Directive[pdm.U] =
toStrictEntity(StrictForm.toStrictTimeout).wrap { pdm() }
}
@pre213
def formFields(pdm: FieldMagnet): pdm.R =
pdm.convert(toStrictEntity(StrictForm.toStrictTimeout).wrap { pdm() })

/**
* Superclass for FormFieldDirectives to provide bridge methods with the old signatures for binary compatibility
*
* Internal API
*/
@InternalApi
trait FormFieldDirectivesCompat {
import FormFieldDirectives.FieldMagnet
@deprecated("Bridge method will be removed in the future", "10.1.9")
private[akka] def formField(pdm: FieldMagnet): AnyRef
@deprecated("Bridge method will be removed in the future", "10.1.9")
private[akka] def formFields(pdm: FieldMagnet): AnyRef
/**
* 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
*/
@since213
def formFields(pdm: FieldMagnet): Directive[pdm.U] =
toStrictEntity(StrictForm.toStrictTimeout).wrap { pdm() }
}

object FormFieldDirectives extends FormFieldDirectives {
Expand Down Expand Up @@ -131,13 +139,23 @@ object FormFieldDirectives extends FormFieldDirectives {
sealed trait FieldMagnet {
type U
def apply(): Directive[U]

// Compatibility helper:
// type R = Directive[U]
// but we don't put it in here, so the compiler will produce AnyRef instead of `Directive` as the result type
// of the `formFields` directives above for compatibility reasons. We also need to provide a type-safe conversion function.
type R
def convert(d: Directive[U]): R
}

object FieldMagnet {
implicit def apply[T](value: T)(implicit fdef: FieldDef[T]): FieldMagnet { type U = fdef.U } =
implicit def apply[T](value: T)(implicit fdef: FieldDef[T]): FieldMagnet { type U = fdef.U; type R = Directive[fdef.U] } =
new FieldMagnet {
type U = fdef.U
def apply(): Directive[U] = fdef(value)

type R = Directive[fdef.U]
def convert(d: Directive[fdef.U]): Directive[fdef.U] = d
}
}

Expand Down

0 comments on commit 9acf0e6

Please sign in to comment.