log.Println("Warning:", GetRemoteAddress(req), req.Method, proxiedURI, "Content-Length not provided")
}
- switch err {
+ switch respErr := err.(type) {
case nil:
status = http.StatusOK
resp.Header().Set("Content-Length", fmt.Sprint(expectLength))
err = ContentLengthMismatch
}
}
- case keepclient.BlockNotFound:
- status = http.StatusNotFound
+ case keepclient.Error:
+ if respErr == keepclient.BlockNotFound {
+ status = http.StatusNotFound
+ } else if respErr.Temporary() {
+ status = http.StatusBadGateway
+ } else {
+ status = 422
+ }
default:
- status = http.StatusBadGateway
+ status = http.StatusInternalServerError
}
}
kc := *handler.KeepClient
- var pass bool
- var tok string
- if pass, tok = CheckAuthorizationHeader(kc, handler.ApiTokenCache, req); !pass {
+ ok, token := CheckAuthorizationHeader(kc, handler.ApiTokenCache, req)
+ if !ok {
status, err = http.StatusForbidden, BadAuthorizationHeader
return
}
// Copy ArvadosClient struct and use the client's API token
arvclient := *kc.Arvados
- arvclient.ApiToken = tok
+ arvclient.ApiToken = token
kc.Arvados = &arvclient
// Only GET method is supported
return
}
+ // Get index from all LocalRoots and write to resp
var reader io.Reader
for uuid := range kc.LocalRoots() {
reader, err = kc.GetIndex(uuid, prefix)
return
}
- var readBytes []byte
- readBytes, err = ioutil.ReadAll(reader)
- if err != nil {
- status = http.StatusBadGateway
- return
- }
-
- // Got index for this server; write to resp
- _, err := resp.Write(readBytes)
+ _, err = io.Copy(resp, reader)
if err != nil {
status = http.StatusBadGateway
return