Adding upstream version 3.10.8.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
37e9b6d587
commit
03bfe4079e
356 changed files with 28857 additions and 0 deletions
71
options/http/implementation.go
Normal file
71
options/http/implementation.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// Copyright twenty-panda <twenty-panda@posteo.com>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package http
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type Implementation struct {
|
||||
newMigrationHTTPClient NewMigrationHTTPClientFun
|
||||
skipTLSVerify *bool
|
||||
proxy *string
|
||||
}
|
||||
|
||||
func (o *Implementation) GetNewMigrationHTTPClient() NewMigrationHTTPClientFun {
|
||||
if o.newMigrationHTTPClient == nil {
|
||||
return func() *http.Client {
|
||||
transport := &http.Transport{}
|
||||
if o.GetSkipTLSVerify() {
|
||||
transport.TLSClientConfig = &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
}
|
||||
if o.GetProxy() != "" {
|
||||
proxyURL, err := url.Parse(o.GetProxy())
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("url.Parse %w", err))
|
||||
}
|
||||
transport.Proxy = func(req *http.Request) (*url.URL, error) {
|
||||
return http.ProxyURL(proxyURL)(req)
|
||||
}
|
||||
}
|
||||
return &http.Client{
|
||||
Transport: transport,
|
||||
}
|
||||
}
|
||||
}
|
||||
return o.newMigrationHTTPClient
|
||||
}
|
||||
|
||||
func (o *Implementation) SetNewMigrationHTTPClient(fun NewMigrationHTTPClientFun) {
|
||||
o.newMigrationHTTPClient = fun
|
||||
}
|
||||
|
||||
func (o *Implementation) GetSkipTLSVerify() bool {
|
||||
if o.skipTLSVerify == nil {
|
||||
return false
|
||||
}
|
||||
return *o.skipTLSVerify
|
||||
}
|
||||
|
||||
func (o *Implementation) SetSkipTLSVerify(skipTLSVerify bool) {
|
||||
o.skipTLSVerify = &skipTLSVerify
|
||||
}
|
||||
|
||||
func (o *Implementation) GetProxy() string {
|
||||
if o.proxy == nil {
|
||||
return ""
|
||||
}
|
||||
return *o.proxy
|
||||
}
|
||||
|
||||
func (o *Implementation) SetProxy(proxy string) {
|
||||
o.proxy = &proxy
|
||||
}
|
41
options/http/implementation_test.go
Normal file
41
options/http/implementation_test.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// Copyright twenty-panda <twenty-panda@posteo.com>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestImplementation(t *testing.T) {
|
||||
i := Implementation{}
|
||||
|
||||
{
|
||||
newClient := i.GetNewMigrationHTTPClient()
|
||||
assert.NotNil(t, newClient)
|
||||
client := newClient()
|
||||
assert.Nil(t, client.Transport.(*http.Transport).TLSClientConfig)
|
||||
assert.Nil(t, client.Transport.(*http.Transport).Proxy)
|
||||
}
|
||||
|
||||
{
|
||||
i.SetSkipTLSVerify(true)
|
||||
proxy := "https://example.com"
|
||||
i.SetProxy(proxy)
|
||||
|
||||
newClient := i.GetNewMigrationHTTPClient()
|
||||
assert.NotNil(t, newClient)
|
||||
client := newClient()
|
||||
assert.NotNil(t, client.Transport.(*http.Transport).TLSClientConfig)
|
||||
assert.True(t, client.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify)
|
||||
assert.NotNil(t, client.Transport.(*http.Transport).Proxy)
|
||||
proxyURL, err := client.Transport.(*http.Transport).Proxy(nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, proxy, proxyURL.String())
|
||||
}
|
||||
}
|
20
options/http/interface.go
Normal file
20
options/http/interface.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type NewMigrationHTTPClientFun func() *http.Client
|
||||
|
||||
type Interface interface {
|
||||
GetNewMigrationHTTPClient() NewMigrationHTTPClientFun
|
||||
SetNewMigrationHTTPClient(fun NewMigrationHTTPClientFun)
|
||||
GetSkipTLSVerify() bool
|
||||
SetSkipTLSVerify(skipTLSVerify bool)
|
||||
GetProxy() string
|
||||
SetProxy(proxy string)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue