aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/http/receive_pack.go
diff options
context:
space:
mode:
authorAntonio Jesus Navarro Perez <antnavper@gmail.com>2017-06-16 16:06:32 +0200
committerAntonio Jesus Navarro Perez <antnavper@gmail.com>2017-07-04 11:17:26 +0200
commit06f26e2d7096a7e8458e9e9b41e05c8bb83babf6 (patch)
tree98ae3a8168532ce40c06ef2e6a144c6346c42ef3 /plumbing/transport/http/receive_pack.go
parentce6f5b7c82fc6c2c4d41880ed6b26f921dd9c1c3 (diff)
downloadgo-git-06f26e2d7096a7e8458e9e9b41e05c8bb83babf6.tar.gz
transport: http push
Diffstat (limited to 'plumbing/transport/http/receive_pack.go')
-rw-r--r--plumbing/transport/http/receive_pack.go71
1 files changed, 63 insertions, 8 deletions
diff --git a/plumbing/transport/http/receive_pack.go b/plumbing/transport/http/receive_pack.go
index 7a37049..f867f97 100644
--- a/plumbing/transport/http/receive_pack.go
+++ b/plumbing/transport/http/receive_pack.go
@@ -1,30 +1,85 @@
package http
import (
- "errors"
+ "bytes"
+ "fmt"
+ "io"
"net/http"
+ "gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
+ "gopkg.in/src-d/go-git.v4/utils/ioutil"
)
-var errReceivePackNotSupported = errors.New("receive-pack not supported yet")
-
type rpSession struct {
*session
}
func newReceivePackSession(c *http.Client, ep transport.Endpoint, auth transport.AuthMethod) (transport.ReceivePackSession, error) {
- return &rpSession{&session{}}, nil
+ s, err := newSession(c, ep, auth)
+ return &rpSession{s}, err
}
func (s *rpSession) AdvertisedReferences() (*packp.AdvRefs, error) {
-
- return nil, errReceivePackNotSupported
+ return advertisedReferences(s.session, transport.ReceivePackServiceName)
}
-func (s *rpSession) ReceivePack(*packp.ReferenceUpdateRequest) (
+func (s *rpSession) ReceivePack(req *packp.ReferenceUpdateRequest) (
*packp.ReportStatus, error) {
+ url := fmt.Sprintf(
+ "%s/%s",
+ s.endpoint.String(), transport.ReceivePackServiceName,
+ )
+
+ buf := bytes.NewBuffer(nil)
+ if err := req.Encode(buf); err != nil {
+ return nil, err
+ }
+
+ res, err := s.doRequest(http.MethodPost, url, buf)
+ if err != nil {
+ return nil, err
+ }
+
+ r, err := ioutil.NonEmptyReader(res.Body)
+ if err != nil {
+ return nil, err
+ }
+
+ rc := ioutil.NewReadCloser(r, res.Body)
+
+ report := packp.NewReportStatus()
+ if err := report.Decode(rc); err != nil {
+ return nil, err
+ }
+
+ return report, report.Error()
+}
+
+func (s *rpSession) doRequest(method, url string, content *bytes.Buffer) (*http.Response, error) {
+ var body io.Reader
+ if content != nil {
+ body = content
+ }
+
+ req, err := http.NewRequest(method, url, body)
+ if err != nil {
+ return nil, plumbing.NewPermanentError(err)
+ }
+
+ applyHeadersToRequest(req, content, s.endpoint.Host(), transport.ReceivePackServiceName)
+ s.applyAuthToRequest(req)
+
+ res, err := s.client.Do(req)
+ if err != nil {
+ return nil, plumbing.NewUnexpectedError(err)
+ }
+
+ if err := NewErr(res); err != nil {
+ _ = res.Body.Close()
+ return nil, err
+ }
- return nil, errReceivePackNotSupported
+ return res, nil
}