Skip to content

Commit

Permalink
s/request/\*request/
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo82148 committed Dec 26, 2022
1 parent 3bee663 commit 13db1ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions ridgenative.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ type requestContextHTTP struct {
UserAgent string `json:"userAgent"`
}

func isV2Request(r request) bool {
func isV2Request(r *request) bool {
return r.Version == "2" || strings.HasPrefix(r.Version, "2.")
}

func (f *lambdaFunction) httpRequestV1(ctx context.Context, r request) (*http.Request, error) {
func (f *lambdaFunction) httpRequestV1(ctx context.Context, r *request) (*http.Request, error) {
// decode header
var headers http.Header
if len(r.MultiValueHeaders) > 0 {
Expand Down Expand Up @@ -147,7 +147,7 @@ func (f *lambdaFunction) httpRequestV1(ctx context.Context, r request) (*http.Re
return req, nil
}

func (f *lambdaFunction) httpRequestV2(ctx context.Context, r request) (*http.Request, error) {
func (f *lambdaFunction) httpRequestV2(ctx context.Context, r *request) (*http.Request, error) {
// build headers
headers := make(http.Header, len(r.Headers))
for k, v := range r.Headers {
Expand Down Expand Up @@ -194,7 +194,7 @@ func (f *lambdaFunction) httpRequestV2(ctx context.Context, r request) (*http.Re
return req, nil
}

func (f *lambdaFunction) decodeBody(r request) (body io.ReadCloser, contentLength int64, err error) {
func (f *lambdaFunction) decodeBody(r *request) (body io.ReadCloser, contentLength int64, err error) {
if r.Body != "" {
var reader io.Reader
if r.IsBase64Encoded {
Expand Down Expand Up @@ -312,7 +312,7 @@ func (rw *responseWriter) Write(data []byte) (int, error) {
return n1 + n2, nil
}

func (rw *responseWriter) lambdaResponseV1() (response, error) {
func (rw *responseWriter) lambdaResponseV1() (*response, error) {
body := rw.encodeBody()

// fall back to headers if multiValueHeaders is not available
Expand All @@ -329,7 +329,7 @@ func (rw *responseWriter) lambdaResponseV1() (response, error) {
h[key] = strings.Join(value, ", ")
}

return response{
return &response{
StatusCode: rw.statusCode,
Headers: h,
MultiValueHeaders: map[string][]string(rw.header),
Expand All @@ -338,7 +338,7 @@ func (rw *responseWriter) lambdaResponseV1() (response, error) {
}, nil
}

func (rw *responseWriter) lambdaResponseV2() (response, error) {
func (rw *responseWriter) lambdaResponseV2() (*response, error) {
body := rw.encodeBody()

// multiValueHeaders is not available in V2; fall back to headers
Expand All @@ -352,7 +352,7 @@ func (rw *responseWriter) lambdaResponseV2() (response, error) {

cookies := rw.header.Values("Set-Cookie")

return response{
return &response{
StatusCode: rw.statusCode,
Headers: h,
Cookies: cookies,
Expand Down Expand Up @@ -439,12 +439,12 @@ func isBinary(contentType string) bool {
return true
}

func (f *lambdaFunction) lambdaHandler(ctx context.Context, req request) (response, error) {
func (f *lambdaFunction) lambdaHandler(ctx context.Context, req *request) (*response, error) {
if isV2Request(req) {
// Lambda Function URLs or API Gateway v2
r, err := f.httpRequestV2(ctx, req)
if err != nil {
return response{}, err
return &response{}, err
}
rw := f.newResponseWriter()
f.mux.ServeHTTP(rw, r)
Expand All @@ -453,7 +453,7 @@ func (f *lambdaFunction) lambdaHandler(ctx context.Context, req request) (respon
// API Gateway v1 or ALB
r, err := f.httpRequestV1(ctx, req)
if err != nil {
return response{}, err
return &response{}, err
}
rw := f.newResponseWriter()
f.mux.ServeHTTP(rw, r)
Expand Down
8 changes: 4 additions & 4 deletions ridgenative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import (
"testing"
)

func loadRequest(path string) (request, error) {
func loadRequest(path string) (*request, error) {
f, err := os.Open(path)
if err != nil {
return request{}, err
return &request{}, err
}
defer f.Close()

var req request
dec := json.NewDecoder(f)
if err := dec.Decode(&req); err != nil {
return request{}, err
return &request{}, err
}
return req, nil
return &req, nil
}

func TestHTTPRequest(t *testing.T) {
Expand Down

0 comments on commit 13db1ba

Please sign in to comment.