Skip to content

Commit

Permalink
Adapt Uri construction to workaround akka http bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chetanmeh committed Jun 21, 2018
1 parent f7aec89 commit 9fcbaa6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ trait AttachmentSupport[DocumentAbstraction <: DocumentSerializer] extends Defau
protected[database] def uriOf(bytesOrSource: Either[ByteString, Source[ByteString, _]], path: => String): Uri = {
bytesOrSource match {
case Left(bytes) => Uri.from(scheme = MemScheme, path = encode(bytes))
case Right(_) => Uri.from(scheme = attachmentScheme, path = path)
case Right(_) => uriFrom(scheme = attachmentScheme, path = path)
}
}

//Not using Uri.from due to https://github.com/akka/akka-http/issues/2080
protected[database] def uriFrom(scheme: String, path: String): Uri = Uri(s"$scheme:$path")

/**
* Constructs a source from inlined attachment contents
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class CouchDbRestStore[DocumentAbstraction <: DocumentSerializer](dbProtocol: St
docStream: Source[ByteString, _])(implicit transid: TransactionId): Future[(DocInfo, Attached)] = {

if (maxInlineSize.toBytes == 0) {
val uri = Uri.from(scheme = attachmentScheme, path = UUID().asString)
val uri = uriFrom(scheme = attachmentScheme, path = UUID().asString)
for {
attached <- Future.successful(Attached(uri.toString, contentType))
i1 <- put(update(doc, attached))
Expand Down Expand Up @@ -549,7 +549,7 @@ class CouchDbRestStore[DocumentAbstraction <: DocumentSerializer](dbProtocol: St
*/
private def getAttachmentName(name: String): String = {
Try(java.util.UUID.fromString(name))
.map(_ => Uri.from(scheme = attachmentScheme, path = name).toString)
.map(_ => uriFrom(scheme = attachmentScheme, path = name).toString)
.getOrElse(name)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class S3AttachmentStore(client: S3Client, bucket: String, prefix: String)(implic
logging: Logging,
materializer: ActorMaterializer)
extends AttachmentStore {
//TODO Use 's3s' for now as due to some bug `Uri.from(scheme="s3") is causing issue
override val scheme = "s3s"
override val scheme = "s3"

override protected[core] implicit val executionContext: ExecutionContext = system.dispatcher

Expand Down

0 comments on commit 9fcbaa6

Please sign in to comment.