-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_conn_context.go
50 lines (39 loc) · 954 Bytes
/
http_conn_context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package http4git
import (
"fmt"
"strings"
"github.com/bitwormhole/gitlib/git/network/pktline"
)
type connectionContext struct {
rawURL string // without 'info/refs'
fullURL string // with 'info/refs'
}
func (inst *connectionContext) init(url string, useSSL bool) error {
isHTTP := strings.HasPrefix(url, "http://")
isHTTPS := strings.HasPrefix(url, "https://")
if useSSL {
if !isHTTPS {
return fmt.Errorf("it's not a HTTPS URL [%v]", url)
}
} else {
if !isHTTPS && !isHTTP {
return fmt.Errorf("it's not a HTTP(or HTTPS) URL [%v]", url)
}
}
inst.rawURL = url
inst.fullURL = url + "/info/refs"
return nil
}
func (inst *connectionContext) open(p *pktline.ConnParams) (pktline.Connection, error) {
service := p.Service
method := p.Method
url := inst.fullURL + "?service=" + service
conn := &httpConn{
context: inst,
url: url,
service: service,
method: method,
}
conn.init(method)
return conn, nil
}