Thanks a lot Olly!
I tried to do some research, here is my code, does it look OK?
```
r.Body = http.MaxBytesReader(w, r.Body, con.SizeLimit)
defer r.Body.Close()
_, err := io.Copy(ioutil.Discard, r.Body)
if err != nil {
ip := r.Header.Get("X-Real-Ip")
fmt.Println("someone just send an oversized request from",
ip)
http.Error(w, "Request body exceeds the size limit", 405)
}else{
fmt.Fprintf(w, "You just sent a legitimate request to the
server!")
}
```
在2025年4月4日星期五 UTC+8 17:46:57<Oliver Lowe> 写道:
> > Is it doable now? If so, from what version?
>
> https://pkg.go.dev/net/http#MaxBytesError
>
> Available since go 1.19 according to the doc.
>
> - Olly
>
--
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 [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/golang-nuts/99378b3d-cb06-47d3-b19a-fbe7eba7f0e9n%40googlegroups.com.