Skip to content
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 internal/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func makeRequest(ctx context.Context, r *Request, c *client.Client, req *http.Re
}

func formatResponse(ctx context.Context, r *Request, resp *http.Response) (io.Reader, error) {
output, err := getOutputValue(r, resp.Header)
output, err := getOutputValue(r, resp)
if err != nil {
return nil, err
}
Expand Down
9 changes: 4 additions & 5 deletions internal/fetch/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func writeOutputToFile(filename string, body io.Reader, size int64, p *core.Prin

}

func getOutputValue(r *Request, hdrs http.Header) (string, error) {
func getOutputValue(r *Request, resp *http.Response) (string, error) {
if r.Output != "" {
// Output was provided directly.
return r.Output, nil
Expand All @@ -67,13 +67,13 @@ func getOutputValue(r *Request, hdrs http.Header) (string, error) {
}

// Attempt to get filename from the Content-Disposition header first.
cdName := getContentDispositionFilename(hdrs)
cdName := getContentDispositionFilename(resp.Header)
if cdName != "" {
return cdName, nil
}

// Get the final path component as the file name.
path := r.URL.Path
path := resp.Request.URL.Path
if !strings.HasPrefix(path, "/") {
path = "/" + path
}
Expand All @@ -83,11 +83,10 @@ func getOutputValue(r *Request, hdrs http.Header) (string, error) {
if after != "" {
return after, nil
}

}

// Fallback to the hostname as the file path and emit a warning.
host := r.URL.Hostname()
host := resp.Request.URL.Hostname()
if host != "" {
return host, nil
}
Expand Down
Loading