add redirection

This commit is contained in:
Adrien Marquès 2018-06-16 18:36:03 +02:00
parent 8c22746375
commit 7e9f4867b0
1 changed files with 14 additions and 1 deletions

View File

@ -125,7 +125,20 @@ func (s *Server) route(res http.ResponseWriter, httpReq *http.Request) {
responseBarebone := implement.NewResponse()
response := callable(parameters, responseBarebone)
/* (2) Build JSON response */
/* (2) Extract http headers */
for k, v := range response.Dump() {
if k == "_REDIRECT_" {
redir, ok := v.(string)
if !ok {
continue
}
res.Header().Add("Location", redir)
res.WriteHeader(308) // permanent redirect
return
}
}
/* (3) Build JSON response */
formattedResponse := response.Dump()
formattedResponse["error"] = response.Err.Code
formattedResponse["reason"] = response.Err.Reason