Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 794b0c7

Browse filesBrowse files
committed
Add deprecated HTTPFallback for package compatibility
Signed-off-by: Derek McGowan <derek@mcg.dev>
1 parent 51c649d commit 794b0c7
Copy full SHA for 794b0c7

1 file changed

+34Lines changed: 34 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎remotes/docker/resolver.go‎

Copy file name to clipboardExpand all lines: remotes/docker/resolver.go
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,3 +763,37 @@ func isTLSError(err error) bool {
763763

764764
return false
765765
}
766+
767+
// HTTPFallback is an http.RoundTripper which allows fallback from https to http
768+
// for registry endpoints with configurations for both http and TLS, such as
769+
// defaulted localhost endpoints.
770+
//
771+
// Deprecated: Use NewHTTPFallback instead.
772+
type HTTPFallback struct {
773+
http.RoundTripper
774+
}
775+
776+
func (f HTTPFallback) RoundTrip(r *http.Request) (*http.Response, error) {
777+
resp, err := f.RoundTripper.RoundTrip(r)
778+
var tlsErr tls.RecordHeaderError
779+
if errors.As(err, &tlsErr) && string(tlsErr.RecordHeader[:]) == "HTTP/" {
780+
// server gave HTTP response to HTTPS client
781+
plainHTTPUrl := *r.URL
782+
plainHTTPUrl.Scheme = "http"
783+
784+
plainHTTPRequest := *r
785+
plainHTTPRequest.URL = &plainHTTPUrl
786+
787+
if r.Body != nil && r.GetBody != nil {
788+
body, err := r.GetBody()
789+
if err != nil {
790+
return nil, err
791+
}
792+
plainHTTPRequest.Body = body
793+
}
794+
795+
return f.RoundTripper.RoundTrip(&plainHTTPRequest)
796+
}
797+
798+
return resp, err
799+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.