github.com/pivotal-cf/go-pivnet/v6@v6.0.2/product_file_link_fetcher.go (about) 1 package pivnet 2 3 import ( 4 "net/http" 5 ) 6 7 type ProductFileLinkFetcher struct { 8 downloadLink string 9 client Client 10 } 11 12 func NewProductFileLinkFetcher(downloadLink string, client Client) ProductFileLinkFetcher { 13 return ProductFileLinkFetcher{downloadLink: downloadLink, client: client} 14 } 15 16 func (p ProductFileLinkFetcher) NewDownloadLink() (string, error) { 17 p.client.HTTP.CheckRedirect = func(req *http.Request, via []*http.Request) error { 18 return http.ErrUseLastResponse 19 } 20 21 resp, err := p.client.MakeRequest("POST", p.downloadLink, http.StatusFound, nil) 22 if err != nil { 23 return "", err 24 } 25 26 defer resp.Body.Close() 27 28 p.client.HTTP.CheckRedirect = nil 29 30 return resp.Header.Get("Location"), nil 31 }