Skip to content

http: use the size and time from JSON directory listings - #10183

Open
A-RYAN-1 wants to merge 1 commit into
rclone:masterfrom
A-RYAN-1:feat/10139-http-listing-metadata
Open

A-RYAN-1 wants to merge 1 commit into
rclone:masterfrom
A-RYAN-1:feat/10139-http-listing-metadata

Conversation

@A-RYAN-1

@A-RYAN-1 A-RYAN-1 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What does this change do?

When the server returns its directory listing as JSON, the http backend now takes the size and modification time of each file from it instead of doing a HEAD request for every file, which is slow on directories with many files.

Two formats are understood, told apart by the fields each item has: nginx (autoindex_format json) and Caddy (file_server browse sent Accept: application/json). JSON in any other format is an error rather than a guess. HTML listings are not read for sizes and times, so they still get the HEAD request as before. There is no option: JSON listings failed before with an unknown content type.

Objects found this way have no Content-Type or header metadata from the server, the same as with --http-no-head.

Linked issue

Fixes #10139

For new or changed backends

This is a listing option on the existing read-only http backend. Besides the new unit tests I have not run test_all against a remote.

Checklist

  • This change is trivial OR it has been discussed and agreed in the linked issue.
  • I have read the contribution guidelines.
  • (If I used AI tools to help write this code) I have read and understood the AI-assisted contributions guidance, and I have tested and take ownership of this change myself.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • (Backend changes only) test_all passes for this backend and if submitting a new backend can provide a test account for the integration tester - see CONTRIBUTING.md.
  • This Pull Request is ready for review.

Open points

  • Design as agreed in the discussion: JSON only, no option, nginx and Caddy detected automatically.
  • Tests: go test ./backend/http/ passes, with cases for nginx, Caddy, unknown JSON formats and a listing that skips HEAD requests for listed files.

@A-RYAN-1
A-RYAN-1 requested a review from ncw as a code owner October 24, 2026 07:10
@A-RYAN-1

Copy link
Copy Markdown
Contributor Author

This implements the listing parsing discussed in #10139 for nginx HTML and JSON, with tests and docs. A review whenever there is time would be great.

@A-RYAN-1

Copy link
Copy Markdown
Contributor Author

The lint job failed on the autogenerated-region check because I had edited docs/content/http.md by hand. I reverted that edit in fd56f78: the option text lives in the Go help, so the docs pick it up when they are regenerated.

@A-RYAN-1

Copy link
Copy Markdown
Contributor Author

The lint fix (fd56f78) is pushed, but the build workflow for that commit is waiting on maintainer approval (action_required), so CI has not run on it yet. Could someone approve the run, and review when there is time? Thank you.

@A-RYAN-1

Copy link
Copy Markdown
Contributor Author

A quick update: all 9 checks are passing on the current head. I am happy to rework the listing detection or the flag name if you would like it different, and can move the discussion to the issue first if that suits you better.

@A-RYAN-1

A-RYAN-1 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Friendly ping for a review when someone has time. The lint failure on the generated docs region is fixed (fd56f78); happy to adjust the approach if you would like it discussed on the issue first.

@A-RYAN-1

A-RYAN-1 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

The issue reporter said on #10139 that they will test this when they can and hope for a quick review. Could someone take a look when there is time? Happy to change anything.

@A-RYAN-1

A-RYAN-1 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

The reporter of #10139 said on the issue that they will test this change. The checks pass and the branch is current; a review is the one thing outstanding. Thanks, and happy to adjust.

@ncw

ncw commented Nov 11, 2026

Copy link
Copy Markdown
Member

I don't really like the whole idea of parsing things out of listings! We currently parse links which are a well defined HTML concept with a tag we can search for. Parsing sizes out of text meant for humans to read sounds very much like a game we are going to lose (I'm getting flashbacks from the FTP LIST parser that we use in rclone here, and FTP LIST is supposed to be standardized :-)

I note that Caddy can provide JSON listings (see https://caddyserver.com/docs/caddyfile/directives/file_server ) as can nginx (see https://nginx.org/en/docs/http/ngx_http_autoindex_module.html ) - perhaps we should parse those only which gives 100% reliable info rather than relying on something for humans which can be configured differently (eg in nginx the size can be configured rounded to the nearest MB).

I don't know if this would satisfy the original submitter or not.

What do you think?

@pladen

pladen commented Nov 11, 2026

Copy link
Copy Markdown

I do definitely agree.
Nginx HTML version of directory listing doesnt include seconds. And it may also change over time.

So i feel like limiting this feature to only 100% JSON reliable output is the better choice.
Caddy can use template for directory listing output. And anyone can also write a script to output a directory listing as JSON in nginx flavour.

No problem for my use case to configure my nginx servers with JSON indexing only.

@A-RYAN-1

Copy link
Copy Markdown
Contributor Author

That makes sense, thanks both. Pushed b314c52: --http-use-listing now reads only the JSON listing (nginx autoindex_format json), which gives an exact size and time, and HTML listings are no longer parsed for them. The help text says so and the tests cover JSON only. I will update the title and description to match.

@A-RYAN-1 A-RYAN-1 changed the title http: use the size and time from nginx directory listings http: use the size and time from JSON directory listings Nov 12, 2026
@A-RYAN-1

Copy link
Copy Markdown
Contributor Author

Friendly ping for a first look at this one. If the approach needs changes, I'm glad to rework it.

@A-RYAN-1

Copy link
Copy Markdown
Contributor Author

Checking in on this one: the JSON-listing-only change from the discussion is in b314c52. A first review would be great whenever you have time.

@ncw

ncw commented Nov 21, 2026

Copy link
Copy Markdown
Member

Thanks for reworking this to JSON only. A couple of design thoughts before merging:

  1. I don't think we need an option. JSON listings currently fail entirely (can't parse content type), so there are no existing users whose behaviour could change, and the nginx JSON size/mtime are the same values HEAD would return. Let's always use them when the listing provides them and drop --http-use-listing.
  2. Let's auto-detect the JSON format rather than assume nginx. Caddy's file_server browse returns JSON (name, size, mod_time, is_dir, …) when sent Accept: application/json. Could you decode into a struct covering both formats, choose based on which fields are present, and return an error for JSON we don't recognise rather than misparse it? Caddy users can then use --http-headers Accept,application/json, which is worth a line in the docs.
  3. Please add Caddy and unknown-JSON cases to TestParseJSON, and squash to a single commit.

…ne#10139

When the server returns its directory listing as JSON, read the size
and modification time of each file from it instead of doing a HEAD
request for every file. Both the nginx (autoindex_format json) and the
Caddy (file_server browse with Accept: application/json) formats are
understood, told apart by the fields each item has. JSON in any other
format is an error rather than a guess. Files that the listing doesn't
describe still get a HEAD request.

HTML listings are not parsed for sizes and times as they are meant for
people and vary between servers.
@A-RYAN-1
A-RYAN-1 force-pushed the feat/10139-http-listing-metadata branch from b314c52 to bd4370f Compare November 22, 2026 06:19
@A-RYAN-1

Copy link
Copy Markdown
Contributor Author

Thanks, all three done in bd4370f (squashed). --http-use-listing is gone and JSON listings are always used. nginx and Caddy are detected from the fields each item has, and any other JSON is an error. TestParseJSON covers nginx, Caddy and unknown formats, and docs/content/http.md has a line on --http-headers Accept,application/json for Caddy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

http - optimize datetime handling for faster transfer

3 participants