Skip to content

Ignore an If-Modified-Since that is not a date, instead of failing the request - #897

Merged
schultek merged 4 commits into
schultek:mainfrom
diegolopezrm:fix/invalid-if-modified-since
Sep 25, 2026
Merged

schultek merged 4 commits into
schultek:mainfrom
diegolopezrm:fix/invalid-if-modified-since

Conversation

@diegolopezrm

Copy link
Copy Markdown
Contributor

Description

Fixes #876, and it is not about styles: standalone in the end — that mode is just what makes the request happen.

The trace in the report lands in shelf_static:

GET /main.css
Error on line 1, column 4: Invalid HTTP date: expected " ".
1 │ Thu,27 Aug 2026 20:33:22 GMT
package:http_parser/src/http_date.dart 61         parseHttpDate
package:shelf/src/request.dart 77                 Request.ifModifiedSince
package:shelf_static/src/static_handler.dart 182  _handleFile

shelf_static reads If-Modified-Since through Request.ifModifiedSince, which throws a FormatException on anything it cannot parse. So a client sending a date without the space after the weekday takes the request down with a 500 and an error dump, and main.css never arrives. That also explains the two shapes the reporter sees — right after a reload, and then now and then on a refresh or from another browser: it happens whenever that client has a cached copy and sends the header back.

RFC 9110 §13.1.3 is explicit that a recipient must ignore an If-Modified-Since field value that is not a valid date. So it is dropped and the file is served as if it had not been sent.

Measured against the real shelf_static, with the exact value from the report:

GET /main.css
before 500
after 200

Two places go through it: jaspr_cli's development proxy, which is what serves the generated styles and what the report hits, and the framework's own static handler in server_handler.dart, which has the same exposure for anything it serves out of web/.

What it does not fix

The second half of the report — main.css being generated after the server reloads — is untouched. It is a sequencing question between the css generation step and the server reload, and worth its own issue if it still bites once the 500 is gone.

Type of Change

  • 🛠️ Bug fix

Tests

packages/jaspr/test/server/conditional_headers_test.dart, three cases against a file handler that reads the header the way shelf_static does: the value from the report is dropped and the file is served, a valid value is passed through and parses to the right instant, and no header stays no header.

dart test -p vm is green in packages/jaspr (184) and dart test test/helpers in packages/jaspr_cli (24).

Fixes #876

`shelf_static` reads the header through `Request.ifModifiedSince`, which
throws a `FormatException` on anything it cannot parse. The request then
failed with a 500 and an error dump, over a header the client sent: the report
has a browser sending `Thu,27 Aug 2026 20:33:22 GMT`, missing the space after
the weekday, and `GET /main.css` answering with a stack trace instead of the
file.

RFC 9110 says a recipient must ignore an `If-Modified-Since` field value that
is not a valid date, so it is dropped and the file is served as if it had not
been sent. The development proxy that serves the generated styles and the
framework's own static handler both go through it.

Fixes schultek#876
@diquoks

diquoks commented Sep 24, 2026

Copy link
Copy Markdown

as the author of original issue, i can say that everything works perfectly after specifying this branch in dependency_overrides

@diegolopezrm

diegolopezrm commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for checking, @diquoks. Good to know it holds up on the machine where it showed up.

The other half of your report, main.css landing after the server reloads, isn't touched by this. If it still bites you once the 500 is gone, open it separately and I'll take a look; that one's about the order of the css step and the reload, not the header.

@github-actions

Copy link
Copy Markdown

Package Version Report

The following packages have been updated:
jaspr_test : 0.23.4 -> 0.23.5
jaspr : 0.23.4 -> 0.23.5
jaspr_builder : 0.23.4 -> 0.23.5
jaspr_cli : 0.23.4 -> 0.23.5

schultek
schultek previously approved these changes Sep 24, 2026

@schultek schultek left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, and thanks @diquoks for confirming this works.

@diegolopezrm Just one nit: can you shorten the changelog entry to one or max two sentences, it doesn't need that much specific detail regarding the exact cause of the issue.

@diquoks

diquoks commented Sep 24, 2026

Copy link
Copy Markdown

The other half of your report, main.css landing after the server reloads, isn't touched by this. If it still bites you once the 500 is gone, open it separately and I'll take a look; that one's about the order of the css step and the reload, not the header.

i'm aware of that, replied to you in the issue earlier:

yeah, i shouldn't have brought that up here, i'll open a new issue a bit later

…fied-since

# Conflicts:
#	packages/jaspr/CHANGELOG.md
@diegolopezrm

Copy link
Copy Markdown
Contributor Author

Rebased on main, the changelog was the only conflict.

About the red Test CLI: it isn't this change, it's build_web_compilers 4.8.6 landing. The scaffolded app can't resolve any more:

Because every version of jaspr_builder from path depends on analyzer ^12.1.0 and
build_web_compilers >=4.8.6 depends on analyzer >=13.3.0 <15.0.0,
jaspr_builder from path is incompatible with build_web_compilers >=4.8.6.

next already has the analyzer bump, so it only bites main. Happy to put a one-line constraint widening on main in its own PR if you want it unblocked before the next release.

@parlough
parlough requested a review from schultek September 25, 2026 06:34

@schultek schultek left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I will fix the dependency issue on main.

@schultek
schultek merged commit 5f458ac into schultek:main Sep 25, 2026
11 checks passed
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.

fix: FormatException when using jaspr serve with styles: standalone

3 participants