Sorry, I wasn't clear enough. I know that panic comes from my code. It throws it. But I wanted to show that error on Decode must not occur because the body is smaller than 8kB. The 2nd example works like this. The only difference between the two examples is just the response is discarded.
Le vendredi 18 juin 2021 à 20:37:11 UTC+2, seank...@gmail.com a écrit : > I think it's working as expected? > The panic originates in your code: > > ``` > err := decoder.Decode(&el) > if err != nil { > panic(err) > } > ``` > > What you should be doing is to break out of the loop and handle the error > (client sending more than you want to read) gracefully > On Friday, June 18, 2021 at 4:32:11 PM UTC+2 jerome....@gmail.com wrote: > >> Hello, >> I am facing to unexpected behavior when I want to limit the maximum body >> request and managing the request/response as streaming way. >> >> With this code https://play.golang.org/p/eN2XEpiPdhn, when I send the >> request, I have this unexpected error (whatever the max size): >> >> ``` >> 2021/06/18 15:48:49 http: panic serving 127.0.0.1:39024: http: invalid >> Read on closed Body >> goroutine 6 [running]: >> net/http.(*conn).serve.func1(0xc000110960) >> net/http/server.go:1824 +0x153 >> panic(0x671b60, 0xc000012af0) >> runtime/panic.go:971 +0x499 >> main.serve(0x713cd0, 0xc0001480e0, 0xc000164000) >> autodebit/service/order/cmd/main.go:32 +0x3b7 >> net/http.HandlerFunc.ServeHTTP(0x6d2608, 0x713cd0, 0xc0001480e0, >> 0xc000164000) >> net/http/server.go:2069 +0x44 >> net/http.serverHandler.ServeHTTP(0xc000148000, 0x713cd0, 0xc0001480e0, >> 0xc000164000) >> net/http/server.go:2887 +0xa3 >> net/http.(*conn).serve(0xc000110960, 0x714180, 0xc000028280) >> net/http/server.go:1952 +0x8cd >> created by net/http.(*Server).Serve >> net/http/server.go:3013 +0x39b >> ``` >> >> But if I discard the response (via io.Discard) that works as expected >> https://play.golang.org/p/ZOJQz6EC--V >> >> I don't understand what it is going wrong. Can I use http.MaxBytesReader >> when I send response as streaming way? >> >> Thanks for your help >> Jérôme >> >> the body file seems too big to be in attach, I put it on >> https://sharetext.me/iveuebzrfq >> the curl cmd: >> curl POST 'http://127.0.0.1:8081' --data-binary '@body.jsonl' >> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a7786512-1390-4b0a-86bc-cd5e9ef0b916n%40googlegroups.com.