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

Akka-HTTP backend #208

Closed
wants to merge 40 commits into from
Closed

Akka-HTTP backend #208

wants to merge 40 commits into from

Conversation

2m
Copy link

@2m 2m commented Dec 22, 2017

This is a PR for a new Play WS backend based on Akka Http.

Currently it supports basic functionality. Missing bigger features for AHC backend parity are listed in #207

This PR adds a new project play-akka-http-ws-standalone which is the Akka Http backend implementation. Tests covering the functionality have been added to integration-tests project and cover Akka Http and AHC backends for both Scala and Java APIs.

You can also try the new backend by adding the following dependency to your project:

resolvers += Resolver.bintrayRepo("2m", "maven")
libraryDependencies += "com.typesafe.play" %% "play-akka-http-ws-standalone" % "1.0.0+62-7728dc21"

@2m
Copy link
Author

2m commented Jan 23, 2018

Rebased on top of the current master to fix merge conflicts.

}
override def actorClass = classOf[InetAddressDnsResolver]
override def managerClass = classOf[SimpleDnsManager]
}
Copy link
Member

Choose a reason for hiding this comment

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

good :)

Copy link
Member

@gmethvin gmethvin left a comment

Choose a reason for hiding this comment

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

This generally looks good. I just had a few questions/suggestions.

*
* @return the response body parsed as a String using the above algorithm.
*/
override def body: String =
Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with this implementation but the comment is wrong because it's using UTF-8 all the time.

Copy link
Member

Choose a reason for hiding this comment

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

The same applies to Java version.

StandaloneAkkaHttpWSRequest(url)
} catch {
case ex: IllegalUriException => throw new IllegalArgumentException(ex.getMessage, ex)
case NonFatal(ex) => throw ex
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to catch and rethrow here?


final class StandaloneAkkaHttpWSClient private ()(
implicit
val sys: ActorSystem, val mat: Materializer, val ctx: HttpsConnectionContext
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the newline before this line?

if (headers.containsKey(header.name())) {
headers.get(header.name()).add(header.value());
}
else {
Copy link
Member

Choose a reason for hiding this comment

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

extra newline (we probably should set up a code formatter on this project...)

*/
@Override
public Map<String, List<String>> getHeaders() {
final Map<String, List<String>> headers = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a map with case-insensitive ordering?

Copy link
Member

@marcospereira marcospereira Jan 30, 2018

Choose a reason for hiding this comment

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

Yes. See #234.

Edit: For now I think @2m is keeping Akka HTTP implementation consistent with AHC.

// Akka Http implementation of WS
//---------------------------------------------------------------

lazy val `play-akka-http-ws-standalone` = project
Copy link
Member

Choose a reason for hiding this comment

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

I think it might be worth naming play-akka-http-ws-experimental, since this is still in development and we could possibly change APIs. WDYT @marcospereira?

Copy link
Member

Choose a reason for hiding this comment

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

Agree.

It would be consistent with the way we changed from Netty to Akka HTTP on the server backend. It is also easier to set users expectations.

*/
override def withHttpHeaders(headers: (String, String)*): Self =
copy(request = request.withHeaders(headers
.map { case (name, value) => HttpHeader.parse(name, value) }
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this will just discard headers Akka HTTP considers invalid. Maybe we can warn instead?

*/
override def headers: Map[String, Seq[String]] =
request.headers
.map(h => HttpHeader.parse(h.name().toLowerCase, h.value()))
Copy link
Member

Choose a reason for hiding this comment

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

Why are we parsing the headers again here?

testOptions in Test := Seq(Tests.Argument(TestFrameworks.JUnit, "-a", "-v"))
)
.settings(
// The scaladoc generation
Copy link
Member

Choose a reason for hiding this comment

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

Is this a TODO?

@@ -0,0 +1,15 @@
package akka.io
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to have this inside akka.io package instead of play.api.ws?

withClient() { client =>
// FIXME configure ssl context with custom cert and enable SSL test for AHC
if (client.isInstanceOf[StandaloneAhcWSClient])
success
Copy link
Member

Choose a reason for hiding this comment

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

pending?

}
}

"round trip XML" in {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe also have a test for JSON?

}
}

// FIXME this is different from Scala API but this is how AHC implementation is
Copy link
Member

Choose a reason for hiding this comment

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

This is a bug, but I think we can fix it after merging your PR.

Copy link
Member

Choose a reason for hiding this comment

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

See #234

withClient() { client =>
// FIXME configure ssl context with custom cert and enable SSL test for AHC
if (client.isInstanceOf[StandaloneAhcWSClient])
success
Copy link
Member

Choose a reason for hiding this comment

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

Same as the Scala version. Should be pending.

this.ctx = ctx;
}

/**
Copy link
Member

@marcospereira marcospereira Jan 30, 2018

Choose a reason for hiding this comment

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

Code format is weird.

.equals(akka.http.scaladsl.model.ContentTypes.NoContentType()) ? null : response.entity().getContentType().toString();
}

/**
Copy link
Member

Choose a reason for hiding this comment

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

No need to duplicate Java docs here since javadoc will do that already. The same applies to other methods and classes.

final ResponseEntity strictEntity = response.entity()
.toStrict(UNMARSHAL_TIMEOUT.toMillis(), mat)
.toCompletableFuture()
.get(UNMARSHAL_TIMEOUT.toNanos(), TimeUnit.NANOSECONDS);
Copy link
Member

@marcospereira marcospereira Jan 30, 2018

Choose a reason for hiding this comment

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

So this is also different from AHC implementation, right? I don't think we have a timeout when reading strict entities in AHC. Maybe we need a more descriptive exception message below to instruct users that they need to use getBodyAsSource.

@2m
Copy link
Author

2m commented Feb 18, 2018

Closing the akka-http backend related tickets for now. These will be handled in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants