Feature: add basic api for proxy provider

This commit is contained in:
Dreamacro
2019-12-11 17:31:15 +08:00
parent 29cf3ca0ef
commit 95e9ae2d8d
6 changed files with 129 additions and 10 deletions

View File

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"strconv"
"time"
@ -30,13 +29,9 @@ func proxyRouter() http.Handler {
return r
}
// When name is composed of a partial escape string, Golang does not unescape it
func parseProxyName(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
name := chi.URLParam(r, "name")
if newName, err := url.PathUnescape(name); err == nil {
name = newName
}
name := getEscapeParam(r, "name")
ctx := context.WithValue(r.Context(), CtxKeyProxyName, name)
next.ServeHTTP(w, r.WithContext(ctx))
})