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
+9.1k Golang : Simple histogram example
+19.4k Golang : Fix cannot download, $GOPATH not set error
+3.7k Java : Random alphabets, alpha-numeric or numbers only string generator
+11.6k Golang : Display a text file line by line with line number example
+9.7k Golang : Detect number of active displays and the display's resolution
+19k Golang : Padding data for encryption and un-padding data for decryption
+22.4k Golang : Read directory content with filepath.Walk()
+9.4k Golang : Web(Javascript) to server-side websocket example
+10.6k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+19.2k Golang : Check whether a network interface is up on your machine
+25.2k Golang : Storing cookies in http.CookieJar example
+10.4k Golang : Meaning of omitempty in struct's field tag