Skip to content

Commit

Permalink
Merge pull request #914 from stripe/brandur-update-webhook-example
Browse files Browse the repository at this point in the history
Update webhook handler example to use `http.MaxBytesReader`
  • Loading branch information
brandur-stripe authored Aug 12, 2019
2 parents 1d97ad6 + 67eacb8 commit b7fac25
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions webhook/client_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (

func Example() {
http.HandleFunc("/webhook", func(w http.ResponseWriter, req *http.Request) {
// Protects against a malicious client streaming us an endless requst
// body
const MaxBodyBytes = int64(65536)
req.Body = http.MaxBytesReader(w, req.Body, MaxBodyBytes)

body, err := ioutil.ReadAll(req.Body)
if err != nil {
Expand Down

0 comments on commit b7fac25

Please sign in to comment.