Пример #1
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
}
Пример #2
0
func dispatchRequest(cc *http.ClientConn, request *http.Request, rc map[int]func(*http.Response) os.Error) (err os.Error) {
	if cc == nil {
		cc, err = dialHTTP(request.Host, request.URL.Scheme)
	}
	if err != nil {
		return
	}
	resp, err := cc.Do(request)
	if resp != nil && (err == nil || err == http.ErrPersistEOF) {
		if rcf, ok := rc[resp.StatusCode]; ok {
			return rcf(resp)
		}
		if rcf, ok := rc[-1]; ok {
			return rcf(resp)
		}
		// If you don't handle your errors, you won't be able to spot a persistant connection closing!
		err = os.NewError("No response handler for code")
	}
	return
}