aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go')
-rw-r--r--vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go64
1 files changed, 41 insertions, 23 deletions
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go
index 5f41251..20a41d4 100644
--- a/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go
+++ b/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go
@@ -14,6 +14,7 @@ import (
"strings"
"time"
+ "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
)
@@ -46,14 +47,29 @@ var BuildHandler = request.NamedHandler{Name: "awssdk.rest.Build", Fn: Build}
func Build(r *request.Request) {
if r.ParamsFilled() {
v := reflect.ValueOf(r.Params).Elem()
- buildLocationElements(r, v)
+ buildLocationElements(r, v, false)
buildBody(r, v)
}
}
-func buildLocationElements(r *request.Request, v reflect.Value) {
+// BuildAsGET builds the REST component of a service request with the ability to hoist
+// data from the body.
+func BuildAsGET(r *request.Request) {
+ if r.ParamsFilled() {
+ v := reflect.ValueOf(r.Params).Elem()
+ buildLocationElements(r, v, true)
+ buildBody(r, v)
+ }
+}
+
+func buildLocationElements(r *request.Request, v reflect.Value, buildGETQuery bool) {
query := r.HTTPRequest.URL.Query()
+ // Setup the raw path to match the base path pattern. This is needed
+ // so that when the path is mutated a custom escaped version can be
+ // stored in RawPath that will be used by the Go client.
+ r.HTTPRequest.URL.RawPath = r.HTTPRequest.URL.Path
+
for i := 0; i < v.NumField(); i++ {
m := v.Field(i)
if n := v.Type().Field(i).Name; n[0:1] == strings.ToLower(n[0:1]) {
@@ -72,6 +88,9 @@ func buildLocationElements(r *request.Request, v reflect.Value) {
if !m.IsValid() {
continue
}
+ if field.Tag.Get("ignore") != "" {
+ continue
+ }
var err error
switch field.Tag.Get("location") {
@@ -83,6 +102,10 @@ func buildLocationElements(r *request.Request, v reflect.Value) {
err = buildURI(r.HTTPRequest.URL, m, name)
case "querystring":
err = buildQueryString(query, m, name)
+ default:
+ if buildGETQuery {
+ err = buildQueryString(query, m, name)
+ }
}
r.Error = err
}
@@ -92,7 +115,9 @@ func buildLocationElements(r *request.Request, v reflect.Value) {
}
r.HTTPRequest.URL.RawQuery = query.Encode()
- updatePath(r.HTTPRequest.URL, r.HTTPRequest.URL.Path)
+ if !aws.BoolValue(r.Config.DisableRestProtocolURICleaning) {
+ cleanPath(r.HTTPRequest.URL)
+ }
}
func buildBody(r *request.Request, v reflect.Value) {
@@ -156,10 +181,11 @@ func buildURI(u *url.URL, v reflect.Value, name string) error {
return awserr.New("SerializationError", "failed to encode REST request", err)
}
- uri := u.Path
- uri = strings.Replace(uri, "{"+name+"}", EscapePath(value, true), -1)
- uri = strings.Replace(uri, "{"+name+"+}", EscapePath(value, false), -1)
- u.Path = uri
+ u.Path = strings.Replace(u.Path, "{"+name+"}", value, -1)
+ u.Path = strings.Replace(u.Path, "{"+name+"+}", value, -1)
+
+ u.RawPath = strings.Replace(u.RawPath, "{"+name+"}", EscapePath(value, true), -1)
+ u.RawPath = strings.Replace(u.RawPath, "{"+name+"+}", EscapePath(value, false), -1)
return nil
}
@@ -193,25 +219,17 @@ func buildQueryString(query url.Values, v reflect.Value, name string) error {
return nil
}
-func updatePath(url *url.URL, urlPath string) {
- scheme, query := url.Scheme, url.RawQuery
+func cleanPath(u *url.URL) {
+ hasSlash := strings.HasSuffix(u.Path, "/")
- hasSlash := strings.HasSuffix(urlPath, "/")
+ // clean up path, removing duplicate `/`
+ u.Path = path.Clean(u.Path)
+ u.RawPath = path.Clean(u.RawPath)
- // clean up path
- urlPath = path.Clean(urlPath)
- if hasSlash && !strings.HasSuffix(urlPath, "/") {
- urlPath += "/"
+ if hasSlash && !strings.HasSuffix(u.Path, "/") {
+ u.Path += "/"
+ u.RawPath += "/"
}
-
- // get formatted URL minus scheme so we can build this into Opaque
- url.Scheme, url.Path, url.RawQuery = "", "", ""
- s := url.String()
- url.Scheme = scheme
- url.RawQuery = query
-
- // build opaque URI
- url.Opaque = s + urlPath
}
// EscapePath escapes part of a URL path in Amazon style