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
+4.8k Golang : A program that contain another program and executes it during run-time
+25.3k Golang : Get current file path of a file or executable
+7.2k Golang : Use modern ciphers only in secure connection
+14.4k Golang : How to pass map to html template and access the map's elements
+6k Golang : Convert Chinese UTF8 characters to Pin Yin
+10.8k Android Studio : Checkbox for user to select options example
+12.3k Golang : 2 dimensional array example
+5.4k Golang : Return multiple values from function
+30.6k Golang : Remove characters from string example
+3.7k Java : Random alphabets, alpha-numeric or numbers only string generator
+18.4k Golang : How to get hour, minute, second from time?
+16.5k Golang : Check if a string contains multiple sub-strings in []string?