Пример #1
1
func debugFailf(out io.Writer, body bool, s string, v ...interface{}) func(*http.Response) os.Error {
	return func(in *http.Response) os.Error {
		ob, _ := http.DumpResponse(in, body)
		out.Write(ob)
		return os.NewError(fmt.Sprintf(s, v...))
	}
}
Пример #2
0
func (self *Service) DescribeInstances(id *aws.Signer, filter http.Values, ic chan Instance) (err os.Error) {
	if filter == nil {
		filter = http.Values{}
	}
	filter.Set("Action", "DescribeInstances")
	req := aws.NewRequest(self.URL, "GET", nil, filter)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	if err != nil {
		return
	}
	resp, err := self.conn.Request(req)
	if err == nil {
		defer resp.Body.Close()
		xresp := describeInstancesResponse{}
		err := xml.Unmarshal(resp.Body, &xresp)
		if err == nil {
			log.Printf("XRESP == %+v", xresp)
		} else {
			log.Printf("XERR == %+v", err)
		}
		ob, _ := http.DumpResponse(resp, true)
		os.Stdout.Write(ob)
	}

	return
}
Пример #3
0
func (self *Domain) GetAttribute(s *aws.Signer, item string, attrs AttributeList, consist bool) (a []Attribute, err os.Error) {
	var resp *http.Response

	vl := attrs.Values(ATTRIBUTE_LIST)

	vl.Set("Action", "GetAttributes")
	vl.Set("DomainName", self.Name)
	vl.Set("ItemName", item)

	if consist {
		vl.Set("ConsistentRead", "true")
	}

	req := aws.NewRequest(self.URL, "GET", nil, vl)
	err = s.SignRequestV2(req, aws.Canonicalize, DEFAULT_API_VERSION, 0)
	if err == nil {
		resp, err = self.conn.Request(req)
	}
	if err == nil {
		defer resp.Body.Close()
		err = aws.CodeToError(resp.StatusCode)
	}
	if err == nil {
		var response getattributesresponse
		ob, _ := http.DumpResponse(resp, true)
		os.Stdout.Write(ob)
		err = xml.Unmarshal(resp.Body, &response)
		if err == nil {
			a = response.Attributes
		}
	}
	return
}
Пример #4
0
// Adds common parameters to the "params" map, signs the request,
// adds the signature to the "params" map and sends the request
// to the server.  It then unmarshals the response in to the "resp"
// parameter using xml.Unmarshal()
func (mt *MTurk) query(params map[string]string, operation string, resp interface{}) os.Error {
	service := MTURK_SERVICE
	timestamp := time.UTC().Format(TIMESTAMP_FORMAT)

	params["AWSAccessKeyId"] = mt.Auth.AccessKey
	params["Service"] = service
	params["Timestamp"] = timestamp
	params["Operation"] = operation

	// make a copy
	url := *mt.URL

	sign(mt.Auth, service, operation, timestamp, params)
	url.RawQuery = multimap(params).Encode()
	r, err := http.Get(url.String())
	if err != nil {
		return err
	}
	dump, _ := http.DumpResponse(r, true)
	println("DUMP:\n", string(dump))
	if r.StatusCode != 200 {
		return os.NewError(fmt.Sprintf("%d: unexpected status code", r.StatusCode))
	}
	err = xml.Unmarshal(r.Body, resp)
	r.Body.Close()
	return err
}
Пример #5
0
Файл: main.go Проект: tobi/tinny
func pipeRequestResponse(server, client net.Conn) os.Error {

	// Read request from wire
	req, err := http.ReadRequest(bufio.NewReader(client))
	if err != nil {
		return err
	}

	rawReq, err := http.DumpRequest(req, true)
	if err != nil {
		return err
	}

	// forward it on
	server.Write(rawReq)

	// Read response from wire
	resp, err := http.ReadResponse(bufio.NewReader(server), req)
	if err != nil {
		return err
	}

	rawResp, err := http.DumpResponse(resp, true)
	if err != nil {
		return err
	}

	log.Printf("%s %s [%s]", req.Method, req.RawURL, resp.Status)

	// forward it on
	client.Write(rawResp)

	return nil
}
Пример #6
0
Файл: http.go Проект: vdobler/ft
// Dump response in wire format to dump if non nil.
func dumpRes(res *http.Response, dump io.Writer) {
	if dump != nil {
		rd, err := http.DumpResponse(res, true)
		if err == nil {
			dump.Write(rd)
			dump.Write([]byte("\r\n\r\n======================================================================================\r\n"))
			dump.Write([]byte("======================================================================================\r\n\r\n\r\n"))
		} else {
			error("Cannot dump response: %s", err.String())
		}
	}
}
Пример #7
0
func (self *Domain) Select(id *aws.Signer, what, where string, consist bool, items chan<- Item) (err os.Error) {
	var resp *http.Response

	vl := http.Values{}

	vl.Set("Action", "Select")
	if where != "" {
		where = " where " + where
	}
	vl.Set("SelectExpression", fmt.Sprintf("select %s from %s%s", what, self.Name, where))

	if consist {
		vl.Set("ConsistentRead", "true")
	}
	done := false
	nextToken := ""
	for err == nil && !done {
		vl.Del("NextToken")
		if nextToken != "" {
			vl.Set("NextToken", nextToken)
		}
		req := aws.NewRequest(self.URL, "GET", nil, vl)
		err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_API_VERSION, 0)
		if err == nil {
			resp, err = self.conn.Request(req)
		}
		if err == nil {
			ob, _ := http.DumpResponse(resp, true)
			os.Stdout.Write(ob)
			xresp := selectresponse{}
			err = xml.Unmarshal(resp.Body, &xresp)
			if err == nil {
				fmt.Printf("XML == %+v", xresp)
				for i := range xresp.Items {
					items <- xresp.Items[i]
				}
				nextToken = xresp.NextToken
				done = (nextToken == "")
			}
			resp.Body.Close()
		}
	}
	return
}
Пример #8
0
// NB: Length is required as we do not buffer the reader
// NB(2): We do NOT close your reader (hence the io.Reader),
// we wrap it with a NopCloser.
func (self *Bucket) PutKeyReader(id *aws.Signer, key string, r io.Reader, l int64, hdr http.Header) (err os.Error) {
	var resp *http.Response
	hreq := aws.NewRequest(self.key_url(key), "PUT", hdr, nil)
	hreq.ContentLength = l
	hreq.Body = ioutil.NopCloser(io.LimitReader(r, l))
	err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15)
	if err == nil {
		resp, err = self.conn.Request(hreq)
		if err == nil {
			defer resp.Body.Close()
			err = aws.CodeToError(resp.StatusCode)
		}
		if err == aws.ErrorUnexpectedResponse {
			ob, _ := http.DumpResponse(resp, true)
			os.Stdout.Write(ob)
		}
	}
	return
}
Пример #9
0
func (p *MockResponseWriter) String() string {
	resp := new(http.Response)
	resp.StatusCode = p.StatusCode
	resp.Proto = "HTTP/1.1"
	resp.ProtoMajor = 1
	resp.ProtoMinor = 1
	resp.Header = p.Headers
	resp.Body = ioutil.NopCloser(bytes.NewBuffer(p.Buffer.Bytes()))
	resp.ContentLength = int64(p.Buffer.Len())
	if p.Headers.Get("Transfer-Encoding") != "" {
		resp.TransferEncoding = []string{p.Headers.Get("Transfer-Encoding")}
	} else {
		resp.TransferEncoding = nil
	}
	resp.Close = p.Headers.Get("Connection") == "close"
	resp.Trailer = make(http.Header)
	resp.Request = p.Request
	b, _ := http.DumpResponse(resp, true)
	return string(b)
}
Пример #10
0
func (c *Client) req(method, endpoint string, body []byte) (map[string]interface{}, os.Error) {
	const host = "mq-aws-us-east-1.iron.io"
	const apiVersion = "1"
	url := path.Join(host, apiVersion, "projects", c.projectId, endpoint)
	url = "http://" + url + "?oauth=" + c.token
	req, err := http.NewRequest(method, url, bytes.NewBuffer(body))
	if err != nil {
		return nil, err
	}
	if body != nil {
		req.Header.Set("Content-Type", "application/json")
		req.ContentLength = int64(len(body))
	}
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, err
	}

	if c.Debug {
		dump, err := http.DumpResponse(resp, true)
		if err != nil {
			fmt.Println("error dumping response:", err)
		} else {
			fmt.Printf("%s\n", dump)
		}
	}

	jDecoder := json.NewDecoder(resp.Body)
	data := map[string]interface{}{}
	err = jDecoder.Decode(&data)
	if err != nil {
		return nil, err
	}
	resp.Body.Close()

	if resp.StatusCode != 200 {
		msg, _ := data["msg"].(string)
		return nil, &Error{resp.StatusCode, msg}
	}
	return data, nil
}
Пример #11
0
func (self *Service) CreateLoadBalancer(id *aws.Signer, name string, zones []string, listeners []Listener) (err os.Error) {
	parms := http.Values{}
	parms.Set("Action", "CreateLoadBalancer")
	parms.Set("LoadBalancerName", name)
	for zi := range zones {
		parms.Set(Sprintf("AvailabilityZones.members.%d", zi+1), zones[zi])
	}
	for li := range listeners {
		listeners[li].SetValues(parms, li+1)
	}
	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 0)
	if err != nil {
		return
	}
	resp, err := self.conn.Request(req)
	if err == nil {
		defer resp.Body.Close()
		ob, _ := http.DumpResponse(resp, true)
		os.Stdout.Write(ob)
	}
	return

}