From d33094545dfbdbd093add8d7e307407586052ed7 Mon Sep 17 00:00:00 2001 From: Piotr Kubisa Date: Sat, 7 Sep 2019 20:14:53 +0200 Subject: [PATCH] Update url encoding, update deps --- go.mod | 4 ++-- go.sum | 15 ++++++++++----- request.go | 20 +++++++------------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 42e9ef7..9346fa5 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/piotrkubisa/apigo go 1.12 require ( - github.com/aws/aws-lambda-go v1.11.1 + github.com/aws/aws-lambda-go v1.13.1 github.com/pkg/errors v0.8.1 - github.com/stretchr/testify v1.3.0 + github.com/stretchr/testify v1.4.0 ) diff --git a/go.sum b/go.sum index 8e334c6..a3ddd31 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,6 @@ -github.com/aws/aws-lambda-go v1.11.1 h1:wuOnhS5aqzPOWns71FO35PtbtBKHr4MYsPVt5qXLSfI= -github.com/aws/aws-lambda-go v1.11.1/go.mod h1:Rr2SMTLeSMKgD45uep9V/NP8tnbCcySgu04cx0k/6cw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/aws/aws-lambda-go v1.13.1 h1:qVIOD3UrEUo4amwgEBu6AI0CfnBsp71XJEYU05RbQ1k= +github.com/aws/aws-lambda-go v1.13.1/go.mod h1:z4ywteZ5WwbIEzG0tXizIAUlUwkTNNknX4upd5Z5XJM= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= @@ -7,7 +8,11 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/request.go b/request.go index 871bc56..b789d4e 100644 --- a/request.go +++ b/request.go @@ -61,15 +61,11 @@ func omitBasePath(path string, basePath string) string { // CreateRequest provides *http.Request to the RequestBuilder. func (r *Request) CreateRequest(host string) (*http.Request, error) { - u, err := r.ParseURL(host) - if err != nil { - return nil, err - } if err := r.ParseBody(); err != nil { return nil, err } - req, err := http.NewRequest(r.Event.HTTPMethod, u.String(), r.Body) + req, err := http.NewRequest(r.Event.HTTPMethod, r.ParseURL(host).String(), r.Body) if err != nil { return nil, err } @@ -78,7 +74,7 @@ func (r *Request) CreateRequest(host string) (*http.Request, error) { } // ParseURL provides URL (as a *url.URL) to the RequestBuilder. -func (r *Request) ParseURL(host string) (*url.URL, error) { +func (r *Request) ParseURL(host string) *url.URL { // Whether path has been already defined (i.e. processed by previous // function) then use it, otherwise use path from the event. path := r.Path @@ -87,19 +83,17 @@ func (r *Request) ParseURL(host string) (*url.URL, error) { } // Parse URL to *url.URL - u, err := url.Parse(path) - if err != nil { - return nil, errors.Wrap(err, "parsing path") + u := &url.URL{ + Scheme: r.Event.Headers["X-Forwarded-Proto"], + Host: host, + Path: path, } // Query-string q := url.Values(r.Event.MultiValueQueryStringParameters) u.RawQuery = q.Encode() - // Host - u.Host = host - - return u, nil + return u } // ParseBody provides body of the request to the RequestBuilder.