diff --git a/.gitignore b/.gitignore index 7b1a9b4..459daa7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ target/ -boot/ \ No newline at end of file +boot/ +.DS_Store +.idea +.idea_modules \ No newline at end of file diff --git a/src/main/scala/S3.scala b/src/main/scala/S3.scala index b5053d4..eec212a 100644 --- a/src/main/scala/S3.scala +++ b/src/main/scala/S3.scala @@ -68,7 +68,7 @@ object S3 { val amzHeaders = req.headers.filter { case (name, _) => name.toLowerCase.startsWith("x-amz") }.foldLeft(Map.empty[String, Set[String]]) { case (m, (name, value)) => - m + (name -> (m(name) + value)) + m + (name -> (m.getOrElse(name, Set.empty[String]) + value)) } val d = new Date req <:< Map("Authorization" -> "AWS %s:%s".format(accessKey, sign(req.method, path, secretKey, d, contentType, contentMd5, amzHeaders)), diff --git a/src/test/scala/S3Spec.scala b/src/test/scala/S3Spec.scala index d23daa2..811943c 100644 --- a/src/test/scala/S3Spec.scala +++ b/src/test/scala/S3Spec.scala @@ -13,6 +13,14 @@ object S3Spec extends Specification { def shouldWeSkip_? = List(access_key, secret_key) must notContain(None).orSkip + def newTempFile = { + val testFile = File.createTempFile("s3specs","bin") + val writer = new FileWriter(testFile) + writer.write("testing") + writer.close + testFile + } + "S3" should { "be able to create a bucket" in { shouldWeSkip_? @@ -24,10 +32,7 @@ object S3Spec extends Specification { "be able to create a file" in { shouldWeSkip_? - val testFile = File.createTempFile("s3specs","bin") - val writer = new FileWriter(testFile) - writer.write("testing") - writer.close + val testFile = newTempFile val r = test / "testing.txt" <<< (testFile, "plain/text") <@ (access_key.get, secret_key.get) Http x (r as_str){ @@ -36,6 +41,15 @@ object S3Spec extends Specification { } } } + "be able to send x-amz headers" in { + shouldWeSkip_? + val testFile = newTempFile + val headers = Map("x-amz-meta-author" -> "john@doe.com") + val r = test / "testing.txt" <<< (testFile, "plain/text") <:< headers <@ (access_key.get, secret_key.get) + Http x (r as_str) { + case (code, _, _, _) => code must be_== (200) + } + } "be able to retrieve a file" in { shouldWeSkip_? Http x(test / "testing.txt" <@ (access_key.get, secret_key.get) as_str) {