Exemple #1
0
// ServeHTTP implements http.Handler.
func (h *LegacyHTTPHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
	st, tag, err := h.Connect(req)
	if err != nil {
		api.SendHTTPError(resp, err)
		return
	}

	var username string
	switch tag := tag.(type) {
	case *names.UserTag:
		username = tag.Name()
	default:
		// TODO(ericsnow) Fail?
		username = tag.Id()
	}

	// We do this *after* authorization, etc. (in h.Connect) in order
	// to prioritize errors that may originate there.
	switch req.Method {
	case "PUT":
		logger.Infof("handling resource upload request")
		response, err := h.HandleUpload(username, st, req)
		if err != nil {
			api.SendHTTPError(resp, err)
			return
		}
		api.SendHTTPStatusAndJSON(resp, http.StatusOK, &response)
		logger.Infof("resource upload request successful")
	default:
		api.SendHTTPError(resp, errors.MethodNotAllowedf("unsupported method: %q", req.Method))
	}
}
Exemple #2
0
// SendHTTPError implements LegacyHTTPHandlerDeps.
func (deps legacyHTTPHandlerDeps) SendHTTPError(resp http.ResponseWriter, err error) {
	api.SendHTTPError(resp, err)
}