github.com/nilium/gitlab-runner@v12.5.0+incompatible/cache/s3/bucket_location_tripper.go (about) 1 package s3 2 3 import ( 4 "bytes" 5 "encoding/xml" 6 "io/ioutil" 7 "net/http" 8 ) 9 10 type bucketLocationTripper struct { 11 bucketLocation string 12 } 13 14 // The Minio Golang library always attempts to query the bucket location and 15 // currently has no way of statically setting that value. To avoid that 16 // lookup, the Runner cache uses the library only to generate the URLs, 17 // forgoing the library's API for uploading and downloading files. The custom 18 // Roundtripper stubs out any network requests that would normally be made via 19 // the library. 20 func (b *bucketLocationTripper) RoundTrip(req *http.Request) (res *http.Response, err error) { 21 var buffer bytes.Buffer 22 err = xml.NewEncoder(&buffer).Encode(b.bucketLocation) 23 if err != nil { 24 return 25 } 26 res = &http.Response{ 27 StatusCode: http.StatusOK, 28 Body: ioutil.NopCloser(&buffer), 29 } 30 return 31 } 32 33 func (b *bucketLocationTripper) CancelRequest(req *http.Request) { 34 // Do nothing 35 }