Skip to content

Commit

Permalink
fix: workaround to enable http2 for semaphore
Browse files Browse the repository at this point in the history
  • Loading branch information
ViRb3 committed Mar 29, 2021
1 parent 9b46647 commit 093a8ec
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/builders/selfhosted.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type SelfHostedData struct {
func MakeSelfHosted(data *SelfHostedData) *SelfHosted {
return &SelfHosted{
SelfHostedData: data,
Client: sling.New().Client(MakeClient(true)).
Client: sling.New().Client(MakeClient()).
Base(data.Url).
SetMany(map[string]string{
"Authorization": "Bearer " + data.Key,
Expand Down
6 changes: 4 additions & 2 deletions src/builders/semaphore.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ func MakeSemaphore(data *SemaphoreData) *Semaphore {
return &Semaphore{
data: data,
baseUrl: baseUrl,
client: sling.New().Client(MakeClient(false)).
Base(baseUrl + "api/").
client: sling.New().Client(MakeClient()).
Base(baseUrl+"api/").
// default Go http2 user agent is (accidentally) blocked by the API server
Set("User-Agent", "curl/7.75.0").
SetMany(map[string]string{
"Authorization": "Token " + data.Token,
}),
Expand Down
19 changes: 2 additions & 17 deletions src/builders/shared.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
package builders

import (
"net"
"net/http"
"time"
)

func MakeClient(attemptHttp2 bool) *http.Client {
transport := http.Transport{
// Cloned http.DefaultTransport.
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
ForceAttemptHTTP2: attemptHttp2,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
return &http.Client{Transport: &transport}
func MakeClient() *http.Client {
return http.DefaultClient
}

type Builder interface {
Expand Down

0 comments on commit 093a8ec

Please sign in to comment.