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: add cacheControl to ObjectMetadata #1274

Merged
merged 2 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions s3/src/main/scala/akka/stream/alpakka/s3/javadsl/S3Client.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.util.Optional
import java.util.concurrent.CompletionStage

import scala.compat.java8.FutureConverters._
import scala.compat.java8.OptionConverters._
import akka.{Done, NotUsed}
import akka.actor.ActorSystem
import akka.http.javadsl.model.headers.ByteRange
Expand Down Expand Up @@ -78,7 +79,7 @@ final class ObjectMetadata private[javadsl] (
* as calculated by Amazon S3.
*/
lazy val getETag: Optional[String] =
scalaMetadata.eTag.fold(Optional.empty[String]())(Optional.of)
scalaMetadata.eTag.asJava

/**
* <p>
Expand Down Expand Up @@ -131,7 +132,7 @@ final class ObjectMetadata private[javadsl] (
* @see ObjectMetadata#setContentType(String)
*/
def getContentType: Optional[String] =
scalaMetadata.contentType.fold(Optional.empty[String]())(Optional.of)
scalaMetadata.contentType.asJava

/**
* Gets the value of the Last-Modified header, indicating the date
Expand All @@ -144,22 +145,24 @@ final class ObjectMetadata private[javadsl] (
def getLastModified: DateTime =
scalaMetadata.lastModified

/**
* Gets the optional Cache-Control header
*/
def getCacheControl: Optional[String] =
scalaMetadata.cacheControl.asJava

/**
* Gets the value of the version id header. The version id will only be available
* if the versioning is enabled in the bucket
*
* @return optional version id of the object
*/
def getVersionId: Optional[String] = scalaMetadata.versionId.fold(Optional.empty[String]())(Optional.of)
def getVersionId: Optional[String] = scalaMetadata.versionId.asJava
}

object MultipartUploadResult {
def create(r: CompleteMultipartUploadResult): MultipartUploadResult =
new MultipartUploadResult(Uri.create(r.location),
r.bucket,
r.key,
r.etag,
r.versionId.fold(Optional.empty[String]())(Optional.of))
new MultipartUploadResult(Uri.create(r.location), r.bucket, r.key, r.etag, r.versionId.asJava)
}

object S3Client {
Expand Down
18 changes: 16 additions & 2 deletions s3/src/main/scala/akka/stream/alpakka/s3/scaladsl/S3Client.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import java.time.Instant

import akka.actor.ActorSystem
import akka.http.scaladsl.model._
import akka.http.scaladsl.model.headers.{`Content-Length`, `Last-Modified`, ByteRange, ETag}
import akka.http.scaladsl.model.headers.{
`Cache-Control`,
`Content-Length`,
`Content-Type`,
`Last-Modified`,
ByteRange,
ETag
}
import akka.stream.Materializer
import akka.stream.alpakka.s3.S3Settings
import akka.stream.alpakka.s3.acl.CannedAcl
Expand Down Expand Up @@ -132,7 +139,7 @@ final class ObjectMetadata private (
* @see ObjectMetadata#setContentType(String)
*/
lazy val contentType: Option[String] = metadata.collectFirst {
case h if h.lowercaseName() == "content-type" => h.value
case ct: `Content-Type` => ct.value
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Following the boy scout rule, I improved this.

There are several Content-Type classes: akka.http.scaladsl.model.ContentType, akka.http.scaladsl.model.headers.Content-Length and before #858 we were using the wrong one...

}

/**
Expand All @@ -147,6 +154,13 @@ final class ObjectMetadata private (
case ct: `Last-Modified` => ct.date
}.get

/**
* Gets the optional Cache-Control header
*/
lazy val cacheControl: Option[String] = metadata.collectFirst {
case c: `Cache-Control` => c.value
}

/**
* Gets the value of the version id header. The version id will only be available
* if the versioning is enabled in the bucket
Expand Down