aws / aws/aws-lambda-go

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

Aperta
#577 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
Go
Stelle
3.8k
Fork
578
Merge medio
8h 18m
PR unite (30g)
1

Descrizione

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

Following https://github.com/aws/aws-lambda-go/issues/508,

> The [`http.ResponseWriter`](https://pkg.go.dev/net/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
https://github.com/aws/aws-lambda-go/compare/v1.41.0...v1.42.0

did not get any hits:

> ![image](https://github.com/user-attachments/assets/209c54c0-deb4-46c5-b131-aacc02d5a29a)

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:

```go
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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia dall’implementazione di lambdaurl.Wrap e confronta il comportamento di ResponseWriter con quello di net/http descritto nell’issue. Riproduci localmente tramite lambdaurl l’handler /hello fornito, quindi verifica che una risposta di piccole dimensioni restituisca il Content-Length e il body previsti invece di Content-Length: 0.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
aws, go
Ambito
api, backend, cloud
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.