Page MenuHomeFreeBSD

libfetch: don't include fragments in HTTP requests
ClosedPublic

Authored by gahr on Aug 19 2024, 7:54 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Sep 24, 12:16 PM
Unknown Object (File)
Fri, Sep 20, 3:31 AM
Unknown Object (File)
Thu, Sep 19, 3:13 PM
Unknown Object (File)
Tue, Sep 17, 12:54 AM
Unknown Object (File)
Fri, Sep 13, 3:32 AM
Unknown Object (File)
Thu, Sep 5, 2:10 PM
Unknown Object (File)
Thu, Sep 5, 2:37 AM
Unknown Object (File)
Wed, Sep 4, 10:12 AM
Subscribers

Details

Summary

Fragments are reserved for client-side processing, see
https://www.rfc-editor.org/rfc/rfc9110.html#section-7.1

Also, some servers don't like to receive HTTP requests with fragments.

$ fetch 'https://dropbox.com/a/b'
fetch: https://dropbox.com/a/b: Not Found

$ fetch 'https://dropbox.com/a/b#'
fetch: https://dropbox.com/a/b#: Bad Request

This is a real-world scenario, where some download link from dropbox
(eventually) redirects to an URL with a fragment:

$ fetch -v 'https://www.dropbox.com/sh/<some>/<thing>?dl=1' 2>&1 | grep requesting
requesting https://www.dropbox.com/sh/<some>/<thing>?dl=1
requesting https://www.dropbox.com/scl/fo/<foo>/<bar>?rlkey=<baz>&dl=1
requesting https://<boo>.dl.dropboxusercontent.com/zip_download_get/<some-long-strig>#

See how the last redirect ends with a #.

Currently, libfetch includes the ending fragment and makes it impossible
to download the file.

Test Plan

manually tested

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 59044
Build 55931: arc lint + arc unit

Event Timeline

gahr requested review of this revision.Aug 19 2024, 7:54 AM
des requested changes to this revision.Aug 19 2024, 8:49 AM

This belongs in the URL parser, not in the HTTP client.

This revision now requires changes to proceed.Aug 19 2024, 8:49 AM
In D46318#1056275, @des wrote:

This belongs in the URL parser, not in the HTTP client.

I was unsure whether the URL parser should terminate the doc part at the first fragment or not. The reason I did it in the http module is that I don't know if any other protocols supported by libfetch might use the fragment for anything. E.g., should fetch file:///path/to/file#foo fetch a file named 'file#foo'?

In D46318#1056275, @des wrote:

This belongs in the URL parser, not in the HTTP client.

I was unsure whether the URL parser should terminate the doc part at the first fragment or not. The reason I did it in the http module is that I don't know if any other protocols supported by libfetch might use the fragment for anything. E.g., should fetch file:///path/to/file#foo fetch a file named 'file#foo'?

The URL parser knows which protocol it's dealing with.

Handle fragments while parsing the URL

This revision is now accepted and ready to land.Aug 21 2024, 10:46 AM