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

AWS S3: make raw request URI contain path and query #1923

Merged
merged 3 commits into from
Sep 12, 2019

Conversation

ennru
Copy link
Member

@ennru ennru commented Sep 10, 2019

Purpose

Just pass the URI path and query as Raw-Request-URI so that Amazon S3 understands Alpakka's HTTP requests.

References

Reported in #1919
akka/akka-http#451
#1738
#838

Changes

  • Commit 1 solves the actual problem
  • Commit 2 makes sure the tests shut down the ActorSystems they create

Background Context

As Amazon S3's use of HTTP is non-standard the fix in #1738 introduced a new problem. Originally discussed in akka/akka-http#451 the Raw Request URI needs to be without request scheme and authority.

@ennru ennru requested a review from jrudolph September 10, 2019 11:45
@ennru ennru added this to the 1.1.2 milestone Sep 10, 2019
Copy link
Member

@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.

LGTM

val rawPath = uri.path.toString()

if (rawPath.contains("+")) {
val fixedPath = rawPath.replaceAll("\\+", "%2B")

rawUri.replace(rawPath, fixedPath)
fixedPath + rawUri.drop(rawPath.length)
Copy link
Member

Choose a reason for hiding this comment

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

Ok, under assumption that the rawUri now starts with the path which should be case.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a require(rawUri startsWith rawPath) just to make sure there are no surprises later on?

@@ -185,7 +185,7 @@ class HttpRequestsSpec extends FlatSpec with Matchers with ScalaFutures {
val req = HttpRequests.getDownloadRequest(location)
req.uri.authority.host.toString shouldEqual "bucket.s3.amazonaws.com"
req.uri.path.toString shouldEqual "/test%20folder/1%20+%202%20=%203"
req.headers should contain(`Raw-Request-URI`("https://bucket.s3.amazonaws.com/test%20folder/1%20%2B%202%20=%203"))
req.headers should contain(`Raw-Request-URI`("/test%20folder/1%20%2B%202%20=%203"))
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -185,7 +185,7 @@ class HttpRequestsSpec extends FlatSpec with Matchers with ScalaFutures {
val req = HttpRequests.getDownloadRequest(location)
req.uri.authority.host.toString shouldEqual "bucket.s3.amazonaws.com"
req.uri.path.toString shouldEqual "/test%20folder/1%20+%202%20=%203"
Copy link
Member

Choose a reason for hiding this comment

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

This assertion is a bit useless as it isn't used when Raw-Request-URI is set but it also doesn't hurt to show the distinction here.

@ennru ennru merged commit b22a811 into akka:master Sep 12, 2019
@ennru ennru deleted the s3-raw-url branch September 12, 2019 17:06
ennru added a commit to ennru/alpakka that referenced this pull request Oct 4, 2019
* make raw request URI contains path and query
* Shut down actor systems in tests
@ennru ennru modified the milestones: 1.1.2, 2.0.0 Oct 4, 2019
ennru added a commit that referenced this pull request Oct 8, 2019
[Backport #1923] AWS S3: make raw request URI contains path and query
@ennru
Copy link
Member Author

ennru commented Oct 8, 2019

Backported to 1.1.x with #1963

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

Successfully merging this pull request may close these issues.

2 participants