Example #1
0
// Generates a canonical string based on the http.Request.
// The request must be complete with the only missing field
// the "Signature".
func CanonicalizeRequest(req *http.Request) (cstr string) {
	params := maptools.StringStringsJoin(req.Form, ",", true)
	cmap := maptools.StringStringEscape(params, aws.Escape, aws.Escape)
	cstr = strings.Join([]string{req.Method, req.Host, req.URL.Path,
		maptools.StringStringJoin(cmap, "=", "&", true)}, "\n")
	return
}
Example #2
0
func updateRawQuery(req *http.Request) {
	req.URL.RawQuery = maptools.StringStringJoin(
		maptools.StringStringEscape(
			maptools.StringStringsJoin(req.Form, ",", false),
			Escape, Escape),
		"=", "&", true)
}
Example #3
0
func (self Connection) WriteRequest(req *http.Request) (resp *http.Response, err os.Error) {
	c, err := self.connection()
	req.URL.RawQuery = maptools.StringStringJoin(
		maptools.StringStringEscape(
			maptools.StringStringsJoin(req.Form, ",", false),
			aws.Escape, aws.Escape),
		"=", "&", true)

	if err == nil {
		err = c.Write(req)
		if err != nil {
			return nil, self.abortConnection(err)
		}
	}
	if err == nil {
		resp, err = c.Read()
		if err != nil {
			err = self.abortConnection(err)
			// PersistantEOF is NOT an invalid condition for the request, it simply invalidates the ClientConn.
			if err == http.ErrPersistEOF {
				err = nil
			}
		}
	}
	return
}
Example #4
0
func (self *Request) Sign(id cryptools.NamedSigner) (err os.Error) {
	params := maptools.StringStringsJoin(self.Form, ",", true)
	cmap := maptools.StringStringEscape(params, aws.Escape, aws.Escape)
	cstr := strings.Join([]string{self.Method, self.Host, self.URL.Path,
		maptools.StringStringJoin(cmap, "=", "&", true)}, "\n")
	sig, err := cryptools.SignString64(id, base64.StdEncoding, cryptools.SignableString(cstr))
	if err == nil {
		self.Form["Signature"] = []string{sig}
	}
	return
}
Example #5
0
// Sends an AWS request.
// A simple helper exposed as it is often useful.
//
// If req.Form is not empty, but req.URL.RawQuery is,
// req.RawQuery will be filled with the values from
// req.Form
func SendRequest(cc *http.ClientConn, req *http.Request) (resp *http.Response, err os.Error) {
	if req.URL.RawQuery == "" && len(req.Form) > 0 {
		req.URL.RawQuery = maptools.StringStringJoin(
			maptools.StringStringEscape(
				maptools.StringStringsJoin(req.Form, ",", false),
				http.URLEscape, http.URLEscape),
			"=", "&", true)
	}
	//bb, _ := http.DumpRequest(req, true)
	//os.Stderr.Write(bb)
	err = cc.Write(req)
	if err == nil {
		resp, err = cc.Read(req)
	}
	//bb, _ = http.DumpResponse(resp, true)
	//os.Stderr.Write(bb)
	return
}
Example #6
0
/*
  Converts a requestmap to a string using the specified
  seperators, escaping, and optional sorting by keys.

  Useful for canonicalization of the request map to various AWS services.
*/
func (self RequestMap) ToString(kvsep, pairsep string, kesc, vesc func(string) string, sorted bool) string {
	eMap := maptools.StringStringEscape(self.Values, kesc, vesc)
	return maptools.StringStringJoin(eMap, kvsep, pairsep, sorted)
}