Esempio n. 1
0
// If we know the location of the asset server, redirect to it when / is requested
// and the Accept header supports text/html
func assetServerRedirect(handler http.Handler, assetPublicURL string) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		if req.URL.Path == "/" {
			if httprequest.PrefersHTML(req) {
				http.Redirect(w, req, assetPublicURL, http.StatusFound)
			}
		}
		// Dispatch to the next handler
		handler.ServeHTTP(w, req)
	})
}
Esempio n. 2
0
func (p *ErrorPage) GrantError(err error, w http.ResponseWriter, req *http.Request) (bool, error) {
	glog.Errorf("GrantError: %v", err)
	// Only render html error pages for browser-like things
	if !httprequest.PrefersHTML(req) {
		return false, err
	}

	errorData := ErrorData{}
	errorData.ErrorCode = GrantErrorCode(err)
	errorData.Error = GrantErrorMessage(errorData.ErrorCode)

	p.render.Render(errorData, w, req)
	return true, nil
}