2015-03-19 19:30:55 +00:00
|
|
|
package lfs
|
2013-10-04 17:09:03 +00:00
|
|
|
|
|
|
|
import (
|
2015-03-20 01:55:40 +00:00
|
|
|
"bytes"
|
2013-10-31 22:12:30 +00:00
|
|
|
"encoding/base64"
|
2015-03-19 23:20:39 +00:00
|
|
|
"encoding/json"
|
2014-03-27 14:59:32 +00:00
|
|
|
"errors"
|
2013-10-04 17:09:03 +00:00
|
|
|
"fmt"
|
2015-03-20 18:01:43 +00:00
|
|
|
"github.com/cheggaaa/pb"
|
2015-03-20 17:55:24 +00:00
|
|
|
"github.com/rubyist/tracerx"
|
2013-10-22 18:21:01 +00:00
|
|
|
"io"
|
2015-03-19 23:20:39 +00:00
|
|
|
"io/ioutil"
|
2013-10-04 17:09:03 +00:00
|
|
|
"net/http"
|
2015-03-20 01:55:40 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2015-03-19 23:20:39 +00:00
|
|
|
"regexp"
|
2015-03-20 01:55:40 +00:00
|
|
|
"strconv"
|
2013-10-04 17:09:03 +00:00
|
|
|
)
|
|
|
|
|
2013-12-09 15:34:29 +00:00
|
|
|
const (
|
2015-03-19 21:16:52 +00:00
|
|
|
mediaType = "application/vnd.git-lfs+json; charset-utf-8"
|
2013-12-09 15:34:29 +00:00
|
|
|
)
|
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
var (
|
2015-03-20 17:10:38 +00:00
|
|
|
lfsMediaTypeRE = regexp.MustCompile(`\Aapplication/vnd\.git\-lfs\+json(;|\z)`)
|
2015-03-22 18:32:22 +00:00
|
|
|
jsonMediaTypeRE = regexp.MustCompile(`\Aapplication/json(;|\z)`)
|
2015-03-19 21:16:52 +00:00
|
|
|
objectRelationDoesNotExist = errors.New("relation does not exist")
|
|
|
|
hiddenHeaders = map[string]bool{
|
|
|
|
"Authorization": true,
|
2015-02-12 23:22:54 +00:00
|
|
|
}
|
2015-03-19 23:20:39 +00:00
|
|
|
|
|
|
|
// 401 and 403 print the same default error message
|
|
|
|
defaultErrors = map[int]string{
|
|
|
|
400: "Client error: %s",
|
|
|
|
401: "Authorization error: %s\nCheck that you have proper access to the repository",
|
|
|
|
404: "Repository or object not found: %s\nCheck that it exists and that you have proper access to it",
|
|
|
|
500: "Server error: %s",
|
|
|
|
}
|
2015-03-19 21:16:52 +00:00
|
|
|
)
|
2015-02-12 02:28:42 +00:00
|
|
|
|
2015-02-26 01:09:53 +00:00
|
|
|
type objectResource struct {
|
|
|
|
Oid string `json:"oid,omitempty"`
|
|
|
|
Size int64 `json:"size,omitempty"`
|
|
|
|
Links map[string]*linkRelation `json:"_links,omitempty"`
|
|
|
|
}
|
|
|
|
|
2015-03-20 01:55:40 +00:00
|
|
|
func (o *objectResource) NewRequest(relation, method string) (*http.Request, Creds, error) {
|
2015-02-26 01:13:56 +00:00
|
|
|
rel, ok := o.Rel(relation)
|
|
|
|
if !ok {
|
2015-03-20 01:55:40 +00:00
|
|
|
return nil, nil, objectRelationDoesNotExist
|
2015-02-26 01:13:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-20 01:55:40 +00:00
|
|
|
req, creds, err := newClientRequest(method, rel.Href)
|
2015-02-26 01:13:56 +00:00
|
|
|
if err != nil {
|
2015-03-20 01:55:40 +00:00
|
|
|
return nil, nil, err
|
2015-02-26 01:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for h, v := range rel.Header {
|
|
|
|
req.Header.Set(h, v)
|
|
|
|
}
|
|
|
|
|
2015-03-20 01:55:40 +00:00
|
|
|
return req, creds, nil
|
2015-02-26 01:13:56 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 01:09:53 +00:00
|
|
|
func (o *objectResource) Rel(name string) (*linkRelation, bool) {
|
|
|
|
if o.Links == nil {
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
|
|
|
|
rel, ok := o.Links[name]
|
|
|
|
return rel, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
type linkRelation struct {
|
|
|
|
Href string `json:"href"`
|
|
|
|
Header map[string]string `json:"header,omitempty"`
|
|
|
|
}
|
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
type ClientError struct {
|
|
|
|
Message string `json:"message"`
|
|
|
|
DocumentationUrl string `json:"documentation_url,omitempty"`
|
|
|
|
RequestId string `json:"request_id,omitempty"`
|
2014-04-01 15:17:04 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
func (e *ClientError) Error() string {
|
|
|
|
msg := e.Message
|
|
|
|
if len(e.DocumentationUrl) > 0 {
|
|
|
|
msg += "\nDocs: " + e.DocumentationUrl
|
2013-10-04 17:09:03 +00:00
|
|
|
}
|
2015-03-19 21:16:52 +00:00
|
|
|
if len(e.RequestId) > 0 {
|
|
|
|
msg += "\nRequest ID: " + e.RequestId
|
2014-08-07 17:37:04 +00:00
|
|
|
}
|
2015-03-19 21:16:52 +00:00
|
|
|
return msg
|
2013-10-04 17:09:03 +00:00
|
|
|
}
|
2013-10-22 18:21:01 +00:00
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
func Download(oid string) (io.ReadCloser, int64, *WrappedError) {
|
2015-03-20 01:55:40 +00:00
|
|
|
req, creds, err := newApiRequest("GET", oid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, 0, Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, obj, wErr := doApiRequest(req, creds)
|
|
|
|
if wErr != nil {
|
|
|
|
return nil, 0, wErr
|
|
|
|
}
|
|
|
|
|
|
|
|
req, creds, err = obj.NewRequest("download", "GET")
|
|
|
|
if err != nil {
|
|
|
|
return nil, 0, Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
res, wErr = doHttpRequest(req, creds)
|
|
|
|
if wErr != nil {
|
|
|
|
return nil, 0, wErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.Body, res.ContentLength, nil
|
2015-03-19 21:16:52 +00:00
|
|
|
}
|
2015-01-23 22:11:10 +00:00
|
|
|
|
2015-03-26 18:46:33 +00:00
|
|
|
type byteCloser struct {
|
|
|
|
*bytes.Reader
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *byteCloser) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-03-20 01:55:40 +00:00
|
|
|
func Upload(oidPath, filename string, cb CopyCallback) *WrappedError {
|
|
|
|
oid := filepath.Base(oidPath)
|
|
|
|
file, err := os.Open(oidPath)
|
|
|
|
if err != nil {
|
|
|
|
return Error(err)
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
stat, err := file.Stat()
|
|
|
|
if err != nil {
|
|
|
|
return Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
reqObj := &objectResource{
|
|
|
|
Oid: oid,
|
|
|
|
Size: stat.Size(),
|
|
|
|
}
|
|
|
|
|
|
|
|
by, err := json.Marshal(reqObj)
|
|
|
|
if err != nil {
|
|
|
|
return Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
req, creds, err := newApiRequest("POST", "")
|
|
|
|
if err != nil {
|
|
|
|
return Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
req.Header.Set("Content-Type", mediaType)
|
|
|
|
req.Header.Set("Content-Length", strconv.Itoa(len(by)))
|
2015-03-21 17:30:31 +00:00
|
|
|
req.ContentLength = int64(len(by))
|
2015-03-26 18:46:33 +00:00
|
|
|
req.Body = &byteCloser{bytes.NewReader(by)}
|
2015-03-20 01:55:40 +00:00
|
|
|
|
2015-03-20 17:55:24 +00:00
|
|
|
tracerx.Printf("api: uploading %s (%s)", filename, oid)
|
2015-03-20 01:55:40 +00:00
|
|
|
res, obj, wErr := doApiRequest(req, creds)
|
|
|
|
if wErr != nil {
|
|
|
|
return wErr
|
|
|
|
}
|
|
|
|
|
2015-03-21 17:28:33 +00:00
|
|
|
if res.StatusCode == 200 {
|
2015-03-20 17:13:16 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-03-20 01:55:40 +00:00
|
|
|
req, creds, err = obj.NewRequest("upload", "PUT")
|
|
|
|
if err != nil {
|
|
|
|
return Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(req.Header.Get("Content-Type")) == 0 {
|
|
|
|
req.Header.Set("Content-Type", "application/octet-stream")
|
|
|
|
}
|
|
|
|
req.Header.Set("Content-Length", strconv.FormatInt(reqObj.Size, 10))
|
2015-03-21 17:28:33 +00:00
|
|
|
req.ContentLength = reqObj.Size
|
2015-03-20 18:01:43 +00:00
|
|
|
|
|
|
|
reader := &CallbackReader{
|
|
|
|
C: cb,
|
|
|
|
TotalSize: reqObj.Size,
|
|
|
|
Reader: file,
|
|
|
|
}
|
2015-03-20 18:06:37 +00:00
|
|
|
|
|
|
|
bar := pb.New64(reqObj.Size)
|
2015-03-20 18:01:43 +00:00
|
|
|
bar.SetUnits(pb.U_BYTES)
|
|
|
|
bar.Start()
|
|
|
|
|
|
|
|
req.Body = ioutil.NopCloser(bar.NewProxyReader(reader))
|
2015-03-20 01:55:40 +00:00
|
|
|
|
|
|
|
res, wErr = doHttpRequest(req, creds)
|
|
|
|
if wErr != nil {
|
|
|
|
return wErr
|
|
|
|
}
|
|
|
|
|
|
|
|
if res.StatusCode > 299 {
|
|
|
|
return Errorf(nil, "Invalid status for %s %s: %d", req.Method, req.URL, res.StatusCode)
|
|
|
|
}
|
|
|
|
|
2015-03-22 18:30:27 +00:00
|
|
|
io.Copy(ioutil.Discard, res.Body)
|
|
|
|
res.Body.Close()
|
|
|
|
|
2015-03-20 01:55:40 +00:00
|
|
|
req, creds, err = obj.NewRequest("verify", "POST")
|
|
|
|
if err == objectRelationDoesNotExist {
|
|
|
|
return nil
|
|
|
|
} else if err != nil {
|
|
|
|
return Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
req.Header.Set("Content-Type", mediaType)
|
|
|
|
req.Header.Set("Content-Length", strconv.Itoa(len(by)))
|
2015-03-21 17:30:31 +00:00
|
|
|
req.ContentLength = int64(len(by))
|
2015-03-20 01:55:40 +00:00
|
|
|
req.Body = ioutil.NopCloser(bytes.NewReader(by))
|
2015-03-22 18:30:27 +00:00
|
|
|
res, wErr = doHttpRequest(req, creds)
|
|
|
|
|
|
|
|
io.Copy(ioutil.Discard, res.Body)
|
|
|
|
res.Body.Close()
|
2015-03-20 01:55:40 +00:00
|
|
|
|
|
|
|
return wErr
|
2015-01-23 22:11:10 +00:00
|
|
|
}
|
|
|
|
|
2015-03-20 01:55:40 +00:00
|
|
|
func doHttpRequest(req *http.Request, creds Creds) (*http.Response, *WrappedError) {
|
2015-03-19 23:20:39 +00:00
|
|
|
res, err := DoHTTP(Config, req)
|
|
|
|
|
|
|
|
var wErr *WrappedError
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
wErr = Errorf(err, "Error for %s %s", res.Request.Method, res.Request.URL)
|
|
|
|
} else {
|
|
|
|
if creds != nil {
|
|
|
|
saveCredentials(creds, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
wErr = handleResponse(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
if wErr != nil {
|
|
|
|
if res != nil {
|
|
|
|
setErrorResponseContext(wErr, res)
|
|
|
|
} else {
|
|
|
|
setErrorRequestContext(wErr, req)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, wErr
|
|
|
|
}
|
|
|
|
|
2015-03-26 18:46:33 +00:00
|
|
|
func doApiRequestWithRedirects(req *http.Request, creds Creds, via []*http.Request) (*http.Response, *WrappedError) {
|
2015-03-20 01:55:40 +00:00
|
|
|
res, wErr := doHttpRequest(req, creds)
|
2015-03-26 18:46:33 +00:00
|
|
|
if wErr != nil {
|
|
|
|
return res, wErr
|
|
|
|
}
|
|
|
|
|
|
|
|
if res.StatusCode == 307 {
|
|
|
|
redirectedReq, redirectedCreds, err := newClientRequest(req.Method, res.Header.Get("Location"))
|
|
|
|
if err != nil {
|
|
|
|
return res, Errorf(err, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
via = append(via, req)
|
|
|
|
if seeker, ok := req.Body.(io.Seeker); ok {
|
|
|
|
_, err := seeker.Seek(0, 0)
|
|
|
|
if err != nil {
|
|
|
|
return res, Error(err)
|
|
|
|
}
|
|
|
|
redirectedReq.Body = req.Body
|
|
|
|
redirectedReq.ContentLength = req.ContentLength
|
|
|
|
} else {
|
|
|
|
return res, Errorf(nil, "Request body needs to be an io.Seeker to handle redirects.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = checkRedirect(redirectedReq, via); err != nil {
|
|
|
|
return res, Errorf(err, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return doApiRequestWithRedirects(redirectedReq, redirectedCreds, via)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, wErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func doApiRequest(req *http.Request, creds Creds) (*http.Response, *objectResource, *WrappedError) {
|
|
|
|
via := make([]*http.Request, 0, 4)
|
|
|
|
res, wErr := doApiRequestWithRedirects(req, creds, via)
|
2015-03-20 01:55:40 +00:00
|
|
|
if wErr != nil {
|
|
|
|
return res, nil, wErr
|
|
|
|
}
|
|
|
|
|
|
|
|
obj := &objectResource{}
|
|
|
|
wErr = decodeApiResponse(res, obj)
|
|
|
|
|
|
|
|
if wErr != nil {
|
|
|
|
setErrorResponseContext(wErr, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, obj, wErr
|
|
|
|
}
|
|
|
|
|
2015-03-19 23:20:39 +00:00
|
|
|
func handleResponse(res *http.Response) *WrappedError {
|
|
|
|
if res.StatusCode < 400 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
io.Copy(ioutil.Discard, res.Body)
|
|
|
|
res.Body.Close()
|
|
|
|
}()
|
|
|
|
|
2015-03-20 01:55:40 +00:00
|
|
|
cliErr := &ClientError{}
|
|
|
|
wErr := decodeApiResponse(res, cliErr)
|
|
|
|
if wErr == nil {
|
|
|
|
if len(cliErr.Message) == 0 {
|
|
|
|
wErr = defaultError(res)
|
|
|
|
} else {
|
|
|
|
wErr = Error(cliErr)
|
2015-03-19 23:20:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wErr.Panic = res.StatusCode > 499 && res.StatusCode != 501 && res.StatusCode != 509
|
|
|
|
return wErr
|
|
|
|
}
|
|
|
|
|
2015-03-20 01:55:40 +00:00
|
|
|
func decodeApiResponse(res *http.Response, obj interface{}) *WrappedError {
|
2015-03-20 17:10:38 +00:00
|
|
|
ctype := res.Header.Get("Content-Type")
|
2015-03-22 18:32:22 +00:00
|
|
|
if !(lfsMediaTypeRE.MatchString(ctype) || jsonMediaTypeRE.MatchString(ctype)) {
|
2015-03-20 01:55:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
err := json.NewDecoder(res.Body).Decode(obj)
|
2015-03-22 18:30:27 +00:00
|
|
|
io.Copy(ioutil.Discard, res.Body)
|
|
|
|
res.Body.Close()
|
|
|
|
|
2015-03-20 01:55:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return Errorf(err, "Unable to parse HTTP response for %s %s", res.Request.Method, res.Request.URL)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-03-19 23:20:39 +00:00
|
|
|
func defaultError(res *http.Response) *WrappedError {
|
|
|
|
var msgFmt string
|
|
|
|
|
|
|
|
if f, ok := defaultErrors[res.StatusCode]; ok {
|
|
|
|
msgFmt = f
|
|
|
|
} else if res.StatusCode < 500 {
|
|
|
|
msgFmt = defaultErrors[400] + fmt.Sprintf(" from HTTP %d", res.StatusCode)
|
|
|
|
} else {
|
|
|
|
msgFmt = defaultErrors[500] + fmt.Sprintf(" from HTTP %d", res.StatusCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Error(fmt.Errorf(msgFmt, res.Request.URL))
|
|
|
|
}
|
|
|
|
|
|
|
|
func saveCredentials(creds Creds, res *http.Response) {
|
|
|
|
if creds == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if res.StatusCode < 300 {
|
|
|
|
execCreds(creds, "approve")
|
|
|
|
} else if res.StatusCode == 401 {
|
|
|
|
execCreds(creds, "reject")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
func newApiRequest(method, oid string) (*http.Request, Creds, error) {
|
|
|
|
u, err := Config.ObjectUrl(oid)
|
2015-01-23 22:11:10 +00:00
|
|
|
if err != nil {
|
2015-03-19 21:16:52 +00:00
|
|
|
return nil, nil, err
|
2015-01-23 22:11:10 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
req, creds, err := newClientRequest(method, u.String())
|
|
|
|
if err == nil {
|
|
|
|
req.Header.Set("Accept", mediaType)
|
2015-01-23 22:11:10 +00:00
|
|
|
}
|
2015-03-19 21:16:52 +00:00
|
|
|
return req, creds, err
|
2015-01-23 22:11:10 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
func newClientRequest(method, rawurl string) (*http.Request, Creds, error) {
|
|
|
|
req, err := http.NewRequest(method, rawurl, nil)
|
2014-04-16 15:02:58 +00:00
|
|
|
if err != nil {
|
2015-03-19 21:16:52 +00:00
|
|
|
return req, nil, err
|
2014-04-16 15:02:58 +00:00
|
|
|
}
|
2014-03-27 14:59:32 +00:00
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
req.Header.Set("User-Agent", UserAgent)
|
|
|
|
creds, err := getCreds(req)
|
|
|
|
return req, creds, err
|
2013-10-22 18:21:01 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
func getCreds(req *http.Request) (Creds, error) {
|
|
|
|
if len(req.Header.Get("Authorization")) > 0 {
|
|
|
|
return nil, nil
|
2013-11-02 00:23:37 +00:00
|
|
|
}
|
2013-11-02 00:31:11 +00:00
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
apiUrl, err := Config.ObjectUrl("")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-02-17 18:46:08 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
if req.URL.Scheme == apiUrl.Scheme &&
|
|
|
|
req.URL.Host == apiUrl.Host {
|
|
|
|
creds, err := credentials(req.URL)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-02-17 18:46:08 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
token := fmt.Sprintf("%s:%s", creds["username"], creds["password"])
|
|
|
|
auth := "Basic " + base64.URLEncoding.EncodeToString([]byte(token))
|
|
|
|
req.Header.Set("Authorization", auth)
|
|
|
|
return creds, nil
|
2015-02-17 18:46:08 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 21:16:52 +00:00
|
|
|
return nil, nil
|
2014-08-08 20:02:44 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 23:18:47 +00:00
|
|
|
func setErrorRequestContext(err *WrappedError, req *http.Request) {
|
|
|
|
err.Set("Endpoint", Config.Endpoint())
|
2014-08-08 20:02:44 +00:00
|
|
|
err.Set("URL", fmt.Sprintf("%s %s", req.Method, req.URL.String()))
|
|
|
|
setErrorHeaderContext(err, "Response", req.Header)
|
2014-08-08 17:31:33 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 23:18:47 +00:00
|
|
|
func setErrorResponseContext(err *WrappedError, res *http.Response) {
|
2014-08-08 17:31:33 +00:00
|
|
|
err.Set("Status", res.Status)
|
2014-08-08 20:02:44 +00:00
|
|
|
setErrorHeaderContext(err, "Request", res.Header)
|
2014-08-08 17:31:33 +00:00
|
|
|
setErrorRequestContext(err, res.Request)
|
2013-11-02 00:23:37 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 23:18:47 +00:00
|
|
|
func setErrorHeaderContext(err *WrappedError, prefix string, head http.Header) {
|
2014-08-08 20:02:44 +00:00
|
|
|
for key, _ := range head {
|
|
|
|
contextKey := fmt.Sprintf("%s:%s", prefix, key)
|
|
|
|
if _, skip := hiddenHeaders[key]; skip {
|
|
|
|
err.Set(contextKey, "--")
|
|
|
|
} else {
|
|
|
|
err.Set(contextKey, head.Get(key))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-19 23:20:39 +00:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
defaultErrors[403] = defaultErrors[401]
|
|
|
|
}
|