func TestInputService6ProtocolTestStreamingPayloadCase1(t *testing.T) { svc := NewInputService6ProtocolTest(nil) svc.Endpoint = "https://test" input := &InputService6TestShapeInputShape{ Body: aws.ReadSeekCloser(bytes.NewBufferString("contents")), Checksum: aws.String("foo"), VaultName: aws.String("name"), } req, _ := svc.InputService6TestCaseOperation1Request(input) r := req.HTTPRequest // build request restjson.Build(req) assert.NoError(t, req.Error) // assert body assert.NotNil(t, r.Body) body, _ := ioutil.ReadAll(r.Body) assert.Equal(t, util.Trim(`contents`), util.Trim(string(body))) // assert URL assert.Equal(t, "https://test/2014-01-01/vaults/name/archives", r.URL.String()) // assert headers assert.Equal(t, "foo", r.Header.Get("x-amz-sha256-tree-hash")) }
func UploadObject(svc *s3.S3, bucketName, objKey string, reader io.Reader) error { params := &s3.PutObjectInput{ Body: aws.ReadSeekCloser(reader), Bucket: aws.String(bucketName), Key: aws.String(objKey), ACL: ACLPublicRead, } _, err := svc.PutObject(params) return err }
func operationErrorResp(status int, body string) *http.Response { return &http.Response{ Status: strconv.Itoa(status) + " foobar", StatusCode: status, Proto: "HTTP/1.1", ProtoMinor: 1, ProtoMajor: 1, Body: aws.ReadSeekCloser(bytes.NewReader([]byte(body))), } }
func (cs *clientServer) signRequest(payload []byte) []byte { reqBody := bytes.NewBuffer(payload) // NewRequest never returns an error if the url parses and we just verified // it did above request, _ := http.NewRequest("GET", cs.URL, reqBody) utils.SignHTTPRequest(request, cs.Region, "ecs", cs.CredentialProvider, aws.ReadSeekCloser(reqBody)) request.Header.Add("Host", request.Host) var dataBuffer bytes.Buffer request.Header.Write(&dataBuffer) io.WriteString(&dataBuffer, "\r\n") data := dataBuffer.Bytes() data = append(data, payload...) return data }
func unmarshalBody(r *request.Request, v reflect.Value) { if field, ok := v.Type().FieldByName("_"); ok { if payloadName := field.Tag.Get("payload"); payloadName != "" { pfield, _ := v.Type().FieldByName(payloadName) if ptag := pfield.Tag.Get("type"); ptag != "" && ptag != "structure" { payload := v.FieldByName(payloadName) if payload.IsValid() { switch payload.Interface().(type) { case []byte: defer r.HTTPResponse.Body.Close() b, err := ioutil.ReadAll(r.HTTPResponse.Body) if err != nil { r.Error = awserr.New("SerializationError", "failed to decode REST response", err) } else { payload.Set(reflect.ValueOf(b)) } case *string: defer r.HTTPResponse.Body.Close() b, err := ioutil.ReadAll(r.HTTPResponse.Body) if err != nil { r.Error = awserr.New("SerializationError", "failed to decode REST response", err) } else { str := string(b) payload.Set(reflect.ValueOf(&str)) } default: switch payload.Type().String() { case "io.ReadSeeker": payload.Set(reflect.ValueOf(aws.ReadSeekCloser(r.HTTPResponse.Body))) case "aws.ReadSeekCloser", "io.ReadCloser": payload.Set(reflect.ValueOf(r.HTTPResponse.Body)) default: io.Copy(ioutil.Discard, r.HTTPResponse.Body) defer r.HTTPResponse.Body.Close() r.Error = awserr.New("SerializationError", "failed to decode REST response", fmt.Errorf("unknown payload type %s", payload.Type())) } } } } } } }
func copyMultipartStatusOKUnmarhsalError(r *request.Request) { b, err := ioutil.ReadAll(r.HTTPResponse.Body) if err != nil { r.Error = awserr.New("SerializationError", "unable to read response body", err) return } body := bytes.NewReader(b) r.HTTPResponse.Body = aws.ReadSeekCloser(body) defer r.HTTPResponse.Body.(aws.ReaderSeekerCloser).Seek(0, 0) if body.Len() == 0 { // If there is no body don't attempt to parse the body. return } unmarshalError(r) if err, ok := r.Error.(awserr.Error); ok && err != nil { if err.Code() == "SerializationError" { r.Error = nil return } r.HTTPResponse.StatusCode = http.StatusServiceUnavailable } }