Bug 209546

Summary: [PATCH] libfetch: doesn't support HTTP 307 redirects
Product: Base System Reporter: Roman Bogorodskiy <novel>
Component: binAssignee: Dag-Erling Smørgrav <des>
Status: Closed FIXED    
Severity: Affects Only Me CC: brd
Priority: --- Keywords: patch
Version: CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
proposed fix, v1 none

Description Roman Bogorodskiy freebsd_committer freebsd_triage 2016-05-16 10:24:11 UTC
Created attachment 170348 [details]
proposed fix, v1

Currently, fetch(1) fails to download a file if there's HTTP 307 redirect for it.

For example:

$ fetch https://jigsaw.w3.org/HTTP/300/307.html
fetch: https://jigsaw.w3.org/HTTP/300/307.html: Temporary Redirect
$

However, it should not fail on redirect unless -A flag was given.

Additionally, in verbose mode it manages to download that file.

This appears to happen because in "switch (http_get_reply(conn))" in http_request_body() from http.c there's no case for HTTP_TEMP_REDIRECT, so it fails to "default" that looks like this:

1816 default:
1817 http_seterr(conn->err);
1818 if (!verbose)
1819 goto ouch;

So in verbose mode it goes further and downloads the file, because HTTP_REDIRECT() macro does include check for HTTP_TEMP_REDIRECT.

Fix by handing HTTP_TEMP_REDIRECT in the http_get_reply(conn) switch.
Comment 1 Roman Bogorodskiy freebsd_committer freebsd_triage 2016-05-16 10:25:08 UTC
FWIW, there's a differential revision also: https://reviews.freebsd.org/D6167.
Comment 2 commit-hook freebsd_committer freebsd_triage 2016-05-31 08:28:06 UTC
A commit references this bug:

Author: des
Date: Tue May 31 08:27:40 UTC 2016
New revision: 301027
URL: https://svnweb.freebsd.org/changeset/base/301027

Log:
  r169386 (PR 112515) was incomplete: it treated 307 as an error except
  in verbose mode, and did not handle 308 at all.

  r241840 (PR 172451) added support for 308, but with the same bug.

  Correctly handle both by recognizing them as redirects in all places
  where we check the HTTP result code.

  PR:		112515 173451 209546
  Submitted by:	novel@
  MFC after:	1 week

Changes:
  head/lib/libfetch/http.c
Comment 3 Brad Davis freebsd_committer freebsd_triage 2016-11-16 18:52:53 UTC
Please reopen if this is still an issue.
Comment 4 commit-hook freebsd_committer freebsd_triage 2017-01-10 08:13:58 UTC
A commit references this bug:

Author: des
Date: Tue Jan 10 08:12:56 UTC 2017
New revision: 311864
URL: https://svnweb.freebsd.org/changeset/base/311864

Log:
  MFH (r301027): fix 307 / 308 redirects
  MFH (r310823): fix multi-line CONNECT responses

  PR:		112515 173451 194483 209546

Changes:
_U  stable/10/
  stable/10/lib/libfetch/http.c