mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-19 09:39:59 +00:00
961c878e0d
Switch to using Go modules. This migrates our vendor.json to use Go 1.11's modules system, and replaces the vendor folder with the output of go mod vendor. The vendored code should remain basically the same; I believe some tree shaking of packages and support scripts/licenses/READMEs/etc. happened. This also fixes Travis and our Makefile to no longer use govendor.
44 lines
939 B
Go
44 lines
939 B
Go
package cleanhttp
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
// HandlerInput provides input options to cleanhttp's handlers
|
|
type HandlerInput struct {
|
|
ErrStatus int
|
|
}
|
|
|
|
// PrintablePathCheckHandler is a middleware that ensures the request path
|
|
// contains only printable runes.
|
|
func PrintablePathCheckHandler(next http.Handler, input *HandlerInput) http.Handler {
|
|
// Nil-check on input to make it optional
|
|
if input == nil {
|
|
input = &HandlerInput{
|
|
ErrStatus: http.StatusBadRequest,
|
|
}
|
|
}
|
|
|
|
// Default to http.StatusBadRequest on error
|
|
if input.ErrStatus == 0 {
|
|
input.ErrStatus = http.StatusBadRequest
|
|
}
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// Check URL path for non-printable characters
|
|
idx := strings.IndexFunc(r.URL.Path, func(c rune) bool {
|
|
return !unicode.IsPrint(c)
|
|
})
|
|
|
|
if idx != -1 {
|
|
w.WriteHeader(input.ErrStatus)
|
|
return
|
|
}
|
|
|
|
next.ServeHTTP(w, r)
|
|
return
|
|
})
|
|
}
|