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
+13.7k Golang : Image to ASCII art example
+7.1k Golang : Array mapping with Interface
+7.1k Restart Apache or Nginx web server without password prompt
+7.7k Gogland : Where to put source code files in package directory for rookie
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+46.5k Golang : Marshal and unmarshal json.RawMessage struct example
+10k Golang : Convert octal value to string to deal with leading zero problem
+5.4k Golang : Get S3 or CloudFront object or file information
+8.2k Golang : Metaprogramming example of wrapping a function
+21.5k Golang : How to read float value from standard input ?
+5.7k Get website traffic ranking with Similar Web or Alexa
+10.2k Golang : Text file editor (accept input from screen and save to file)