Skip to content

Commit

Permalink
Merge pull request #2 from dwestheide/fix_amazon_headers
Browse files Browse the repository at this point in the history
Fixing a bug concerning usage of x-amz headers.
  • Loading branch information
Nathan Hamblen committed Oct 23, 2011
2 parents b0498d0 + f50f852 commit 42358c2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .gitignore
@@ -1,2 +1,5 @@
target/
boot/
boot/
.DS_Store
.idea
.idea_modules
2 changes: 1 addition & 1 deletion src/main/scala/S3.scala
Expand Up @@ -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)),
Expand Down
22 changes: 18 additions & 4 deletions src/test/scala/S3Spec.scala
Expand Up @@ -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_?
Expand All @@ -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){
Expand All @@ -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) {
Expand Down

0 comments on commit 42358c2

Please sign in to comment.