add path handler option

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-04-13 11:32:56 +03:00
parent 0eb3c0b452
commit 622a79bd06
3 changed files with 47 additions and 7 deletions

View File

@@ -66,6 +66,14 @@ func (h *httpHandler) Options() server.HandlerOptions {
}
func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
for exp, ph := range h.pathHandlers {
if exp.MatchString(r.URL.String()) {
ph(w, r)
return
}
}
ctx := metadata.NewContext(r.Context(), nil)
defer r.Body.Close()
@@ -76,9 +84,9 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
ct := strings.Split(DefaultContentType, ";")[0]
ct := DefaultContentType
if htype := r.Header.Get("Content-Type"); htype != "" {
ct = strings.Split(htype, ";")[0]
ct = htype
}
var cf codec.Codec
@@ -87,7 +95,7 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case "application/x-www-form-urlencoded":
cf, err = h.newCodec(strings.Split(DefaultContentType, ";")[0])
default:
cf, err = h.newCodec(ct)
cf, err = h.newCodec(strings.Split(ct, ";")[0])
}
if err != nil {