func (s *GitUploadPackService) doRequest(method, url string, content *strings.Reader) (*http.Response, error) { var body io.Reader if content != nil { body = content } req, err := http.NewRequest(method, url, body) if err != nil { return nil, core.NewPermanentError(err) } s.applyHeadersToRequest(req, content) s.applyAuthToRequest(req) res, err := s.Client.Do(req) if err != nil { return nil, core.NewUnexpectedError(err) } if err := NewHTTPError(res); err != nil { return nil, err } return res, nil }
func (r *GitUploadPackInfo) Decode(d *pktline.Decoder) error { if err := r.read(d); err != nil { if err == EmptyGitUploadPackErr { return core.NewPermanentError(err) } return core.NewUnexpectedError(err) } return nil }
func NewHTTPError(r *http.Response) error { if r.StatusCode >= 200 && r.StatusCode < 300 { return nil } err := &HTTPError{r} if r.StatusCode == 404 || r.StatusCode == 401 { return core.NewPermanentError(common.NotFoundErr) } return core.NewUnexpectedError(err) }
func (s *GitUploadPackService) Fetch(r *common.GitUploadPackRequest) (io.ReadCloser, error) { url := fmt.Sprintf("%s/%s", s.endpoint, common.GitUploadPackServiceName) res, err := s.doRequest("POST", url, r.Reader()) if err != nil { return nil, err } h := make([]byte, 8) if _, err := res.Body.Read(h); err != nil { return nil, core.NewUnexpectedError(err) } return res.Body, nil }