Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: lambdaurl.Wrap still does not add Content-Length headers? #577

Open
suntong opened this issue Nov 24, 2024 · 1 comment
Open

BUG: lambdaurl.Wrap still does not add Content-Length headers? #577

suntong opened this issue Nov 24, 2024 · 1 comment

Comments

@suntong
Copy link

suntong commented Nov 24, 2024

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is.

Following #508,

The http.ResponseWriter implementation says the following thing about Content-Type header (and it actually has a note about Content-Length too).

If WriteHeader has not yet been called, Write calls
WriteHeader(http.StatusOK) before writing the data. If the Header
does not contain a Content-Type line, Write adds a Content-Type set
to the result of passing the initial 512 bytes of written data to
DetectContentType. Additionally, if the total size of all written
data is under a few KB and there are no Flush calls, the
Content-Length header is added automatically.

As of right now the lambdaurl.Wrap implementation completely misses this . . .

which get closed as a part of https://github.com/aws/aws-lambda-go/releases/tag/v1.42.0

However a quick search of Content-Length in the change log of
v1.41.0...v1.42.0

did not get any hits:

image

Are the Content-Length headers being added now?

Describe the solution you'd like

Add the Content-Length headers, properly.

Additional context

For a handler like:

				mux.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
					w.WriteHeader(200)
					_, _ = w.Write([]byte("Hello World!"))
				})

I was able to get return from it if I try it locally, However, if using lambdaurl, I got empty returns, i.e., Content-Length: 0.

Please double-check. Thanks

@suntong
Copy link
Author

suntong commented Nov 25, 2024

Describe the solution you'd like

Add the Content-Length headers.

As the Content-Length header is not added by the lib. Ref:
https://github.com/search?q=repo%3Aaws%2Faws-lambda-go+Content-Length&type=code

However, It seems to be more than that for a proper fix, as I tried to add the Content-Length headers myself but it has no effect at all:

	mux.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Length", "12") // len("Hello World!")
		w.WriteHeader(200)
		w.Write([]byte("Hello World!"))

	})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant