Golang net/http.MaxBytesReader() function example
package net/http
Golang net/http.MaxBytesReader() function usage example
package main
import (
"fmt"
"io"
"io/ioutil"
"net/http"
)
func maxByte(w http.ResponseWriter, r *http.Request) {
r.Body = http.MaxBytesReader(w, r.Body, 10)
fmt.Println(io.Copy(ioutil.Discard, r.Body))
}
func main() {
http.HandleFunc("/maxByte", maxByte)
http.ListenAndServe(":8108", nil)
}
NOTE : MaxBytesReader() is useful to prevent malicious attack or accidental large request.
Reference :
Advertisement
Something interesting
Tutorials
+6.5k Golang : Spell checking with ispell example
+18.4k Golang : How to remove certain lines from a file
+20.2k Golang : Compare floating-point numbers
+22.2k Golang : How to run Golang application such as web server in the background or as daemon?
+13.6k Golang : reCAPTCHA example
+8k Golang : What fmt.Println() can do and println() cannot do
+13.2k Golang : Convert(cast) int to int64
+51.9k Golang : How to get time in milliseconds?
+8.8k Golang : Executing and evaluating nested loop in html template
+15.3k Golang : How to get Unix file descriptor for console and file
+13.4k Golang : Read from buffered reader until specific number of bytes
+6k Golang : How to verify input is rune?