From 3e096e91b803c73141e5f6818f260072363edc02 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 16 Jun 2018 22:15:05 +0200 Subject: [PATCH] add 'Authorization' header if not empty into controller parameters --- router.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/router.go b/router.go index a9d4763..4868c14 100644 --- a/router.go +++ b/router.go @@ -121,11 +121,17 @@ func (s *Server) route(res http.ResponseWriter, httpReq *http.Request) { /* (6) Execute and get response ---------------------------------------------------------*/ - /* (1) Execute */ + /* (1) Add optional Authorization header */ + authHeader := httpReq.Header.Get("Authorization") + if len(authHeader) > 0 { + parameters["_AUTHORIZATION_"] = authHeader + } + + /* (2) Execute */ responseBarebone := implement.NewResponse() response := callable(parameters, responseBarebone) - /* (2) Extract http headers */ + /* (3) Extract http headers */ for k, v := range response.Dump() { if k == "_REDIRECT_" { redir, ok := v.(string) @@ -138,7 +144,7 @@ func (s *Server) route(res http.ResponseWriter, httpReq *http.Request) { } } - /* (3) Build JSON response */ + /* (4) Build JSON response */ formattedResponse := response.Dump() formattedResponse["error"] = response.Err.Code formattedResponse["reason"] = response.Err.Reason