Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switched over remaining usage of http.Client to use common transport #137

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion director.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func QueryDirector(source string, directorUrl string) (resp *http.Response, err
// redirect. We use the Location url elsewhere (plus we still need to do the token
// dance!)
var client *http.Client
tr := getTransport()
tr := GetTransport()
client = &http.Client{
Transport: tr,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
Expand Down
10 changes: 5 additions & 5 deletions handle_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func setupTransport() *http.Transport {
}

// function to get/setup the transport (only once)
func getTransport() *http.Transport {
func GetTransport() *http.Transport {
onceTransport.Do(func() {
transport = setupTransport()
})
Expand All @@ -486,7 +486,7 @@ func DownloadHTTP(transfer TransferDetails, dest string, token string) (int64, e

// Create the client, request, and context
client := grab.NewClient()
transport := getTransport()
transport := GetTransport()
if !transfer.Proxy {
transport.Proxy = nil
}
Expand Down Expand Up @@ -829,7 +829,7 @@ Loop:

}

var UploadClient = &http.Client{Transport: getTransport()}
var UploadClient = &http.Client{Transport: GetTransport()}

// Actually perform the Put request to the server
func doPut(request *http.Request, responseChan chan<- *http.Response, errorChan chan<- error) {
Expand Down Expand Up @@ -930,7 +930,7 @@ func walkDavDir(url *url.URL, token string, namespace namespaces.Namespace) ([]s
c := gowebdav.NewClient(rootUrl.String(), "", "")

// XRootD does not like keep alives and kills things, so turn them off.
transport = getTransport()
transport = GetTransport()
c.SetTransport(transport)

files, err := walkDir(url.Path, c)
Expand Down Expand Up @@ -982,7 +982,7 @@ func StatHttp(dest *url.URL, namespace namespaces.Namespace) (uint64, error) {

var resp *http.Response
for {
transport := getTransport()
transport := GetTransport()
if disableProxy {
log.Debugln("Performing HEAD (without proxy)", dest.String())
transport.Proxy = nil
Expand Down
14 changes: 4 additions & 10 deletions namespace-registry/client_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
package nsregistry

import (
"crypto/tls"

"github.com/pkg/errors"

"bufio"
Expand All @@ -36,10 +34,10 @@ import (
"github.com/lestrrat-go/jwx/v2/jwa"
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/lestrrat-go/jwx/v2/jwt"
"github.com/pelicanplatform/pelican"
"github.com/pelicanplatform/pelican/config"
"github.com/pelicanplatform/pelican/director"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)

type clientResponseData struct {
Expand All @@ -65,13 +63,9 @@ func makeRequest(url string, method string, data map[string]interface{}, headers
req.Header.Set(key, val)
}

client := &http.Client{}
if viper.GetBool("TLSSkipVerify") {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = &http.Client{Transport: tr}
}
tr := pelican.GetTransport()
client := &http.Client{Transport: tr}

resp, err := client.Do(req)
if err != nil {
return nil, err
Expand Down
12 changes: 4 additions & 8 deletions origin_ui/advertise.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ package origin_ui

import (
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
"net/url"
"time"

"github.com/pelicanplatform/pelican"
"github.com/pelicanplatform/pelican/director"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -121,13 +121,9 @@ func AdvertiseOrigin() error {

// We should switch this over to use the common transport, but for that to happen
// that function needs to be exported from pelican
client := http.Client{}
if viper.GetBool("TLSSkipVerify") {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = http.Client{Transport: tr}
}
tr := pelican.GetTransport()
client := http.Client{Transport: tr}

resp, err := client.Do(req)
if err != nil {
return errors.Wrap(err, "Failed to start request for director registration")
Expand Down
Loading