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
+12.6k Golang : flag provided but not defined error
+30.8k Golang : Download file example
+13.8k Golang : unknown escape sequence error
+11.3k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+11.2k CodeIgniter : How to check if a session exist in PHP?
+8k Golang : Handle Palindrome string with case sensitivity and unicode
+7.4k Golang : Scanf function weird error in Windows
+7.1k Golang : Get environment variable
+6.1k Golang : Debug with Godebug
+5.4k Golang : Get S3 or CloudFront object or file information
+15.2k Golang : Save(pipe) HTTP response into a file
+15.9k Golang : Update database with GORM example