Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break out timestamping from signing logic for people making their own…
… signed URL's.
- Loading branch information
James D. Nurmi
committed
Jun 24, 2011
1 parent
01a7f2c
commit a153fcd
Showing
2 changed files
with
33 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,36 @@ | ||
package aws | ||
|
||
import ( | ||
"http" | ||
"strconv" | ||
"time" | ||
) | ||
/* | ||
Copyright (c) 2010, Abneptis LLC. | ||
See COPYRIGHT and LICENSE for details. | ||
*/ | ||
|
||
var SQSTimestampFormat = "2006-01-02T15:04:05MST" | ||
var ISO8601TimestampFormat = "2006-01-02T15:04:05Z" | ||
|
||
// Adds a current timestamp to the request (deleting any present timestamp). | ||
// - you may optionally pass in a custom function to create the timestamp value, | ||
// otherwise we default to time.UTC(). | ||
|
||
func Timestamp(req *http.Request, t func() *time.Time) { | ||
if t == nil { | ||
req.Form.Set("Timestamp", time.UTC().Format(ISO8601TimestampFormat)) | ||
} else { | ||
req.Form.Set("Timestamp", t().Format(ISO8601TimestampFormat)) | ||
} | ||
} | ||
|
||
// Adds an expiration message to the request (as opposed to a timestamp) | ||
// You may supply a custom time() function, else time.Seconds() is used. | ||
func Expires(req *http.Request, t func() *time.Time, from_now int64) { | ||
if t == nil { | ||
req.Form.Set("Expires", strconv.Itoa64(time.Seconds() + from_now)) | ||
} else { | ||
req.Form.Set("Expires", strconv.Itoa64(t().Seconds()+from_now)) | ||
} | ||
} |