Skip to content

Commit

Permalink
Add requestUri and remoteAddr
Browse files Browse the repository at this point in the history
  • Loading branch information
abihf committed Nov 8, 2021
1 parent f1a32e3 commit c24f6d5
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions req.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ func NewRequestV2(ctx context.Context, e *events.APIGatewayV2HTTPRequest) (*http
for key, val := range e.QueryStringParameters {
qs = append(qs, url.QueryEscape(key)+"="+url.QueryEscape(val))
}
u := &url.URL{
Path: e.RequestContext.HTTP.Path,
Host: host,
RawPath: e.RawPath,
RawQuery: strings.Join(qs, "&"),
Scheme: e.RequestContext.HTTP.Protocol,
}
req := &http.Request{
Method: e.RequestContext.HTTP.Method,
URL: &url.URL{
Path: e.RequestContext.HTTP.Path,
Host: host,
RawPath: e.RawPath,
RawQuery: strings.Join(qs, "&"),
},
RequestURI: u.RequestURI(),
Method: e.RequestContext.HTTP.Method,
URL: u,

// just hardcode it
Proto: e.RequestContext.HTTP.Protocol,
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,

Expand All @@ -53,6 +56,7 @@ func NewRequestV2(ctx context.Context, e *events.APIGatewayV2HTTPRequest) (*http
TransferEncoding: []string{},
Close: true,
Host: host,
RemoteAddr: e.RequestContext.HTTP.SourceIP,
}

withEvent := attachLambdaEvent(ctx, e)
Expand All @@ -76,13 +80,16 @@ func NewRequest(ctx context.Context, e *events.APIGatewayProxyRequest) (*http.Re
for key, val := range e.QueryStringParameters {
qs = append(qs, url.QueryEscape(key)+"="+url.QueryEscape(val))
}
u := &url.URL{
Scheme: e.RequestContext.Protocol,
Path: e.Path,
RawPath: e.Path,
RawQuery: strings.Join(qs, "&"),
}
req := &http.Request{
Method: e.HTTPMethod,
URL: &url.URL{
Path: e.Path,
RawPath: e.Path,
RawQuery: strings.Join(qs, "&"),
},
Method: e.HTTPMethod,
URL: u,
RequestURI: u.RequestURI(),

// just hardcode it
Proto: "HTTP/1.1",
Expand All @@ -98,6 +105,7 @@ func NewRequest(ctx context.Context, e *events.APIGatewayProxyRequest) (*http.Re
TransferEncoding: []string{},
Close: true,
Host: host,
RemoteAddr: e.RequestContext.Identity.SourceIP,
}

withEvent := attachLambdaEvent(ctx, e)
Expand Down

0 comments on commit c24f6d5

Please sign in to comment.