Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt/rfc2822: add routines explicitly for RFC 9110 #154

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

BurntSushi
Copy link
Owner

It seems that RFC 9110 does not support offsets like -0000 in the
date format, and also requires that days be padded to two digits in all
cases. This meant that Jiff's RFC 2822 output was, strictly speaking,
incompatible with a strict implementation of RFC 9110. For example, it
would output this:

Thu, 1 Jan 1970 00:00:01 -0000

Where RFC 9110 would want this:

Thu, 01 Jan 1970 00:00:01 GMT

I am actually still unclear as to the relationship between
RFC 2822/5322 and RFC 9110, but as far as I know, RFC 2822
has been obsoleted by RFC 5322, but RFC 5322 does not seem
to make any meaningful changes to the datetime format:
https://datatracker.ietf.org/doc/html/rfc5322#section-3.3

But, since it seems like the RFC 9110 format is a subset of the RFC
2822/5322 format, and since MDN clearly stipulates the use of RFC
9110
, we add a new method that outputs a RFC 2822 compatible timestamp
that is explicitly compatible with RFC 9110.

Fixes #151

It seems that RFC 9110 does not support offsets like `-0000` in the
date format, and also requires that days be padded to two digits in all
cases. This meant that Jiff's RFC 2822 output was, strictly speaking,
incompatible with a strict implementation of RFC 9110. For example, it
would output this:

    Thu, 1 Jan 1970 00:00:01 -0000

Where RFC 9110 would want this:

    Thu, 01 Jan 1970 00:00:01 GMT

I am actually still unclear as to the relationship between
RFC 2822/5322 and RFC 9110, but as far as I know, RFC 2822
has been obsoleted by RFC 5322, but RFC 5322 does not seem
to make any meaningful changes to the datetime format:
https://datatracker.ietf.org/doc/html/rfc5322#section-3.3

But, since it seems like the RFC 9110 format is a subset of the RFC
2822/5322 format, and since [MDN clearly stipulates the use of RFC
9110], we add a new method that outputs a RFC 2822 compatible timestamp
that is explicitly compatible with RFC 9110.

Fixes #151

[MDN clearly stipulates the use of RFC 9110]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since
@BurntSushi
Copy link
Owner Author

No idea what's going on with the wasm-pack test. The error is inscrutable and it works locally. Plus, it's happening on master, so I'm going to go ahead and merge this.

@BurntSushi BurntSushi merged commit 2f57962 into master Nov 1, 2024
16 of 17 checks passed
@BurntSushi BurntSushi deleted the ag/rfc2822-tweak branch November 1, 2024 12:25
BurntSushi added a commit to astral-sh/uv that referenced this pull request Nov 1, 2024
This still utilizes the RFC 2822 datetime formatter, but utilizes new
methods [added in jiff 0.1.14] to emit timestamps in a format strictly
compatible with RFC 9110.

It seems like most HTTP servers were pretty flexible and supported RFC
2822 datetime formats, but #8747 shows at least one case where that
isn't true. Given that the [MDN docs prescribe RFC 9110], we defer to
them.

Fixes #8747

[added in jiff 0.1.14]: BurntSushi/jiff#154
[MDN docs prescribe RFC 9110]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since
BurntSushi added a commit to astral-sh/uv that referenced this pull request Nov 1, 2024
This still utilizes the RFC 2822 datetime formatter, but utilizes new
methods [added in jiff 0.1.14] to emit timestamps in a format strictly
compatible with RFC 9110.

It seems like most HTTP servers were pretty flexible and supported RFC
2822 datetime formats, but #8747 shows at least one case where that
isn't true. Given that the [MDN docs prescribe RFC 9110], we defer to
them.

Fixes #8747

[added in jiff 0.1.14]: BurntSushi/jiff#154
[MDN docs prescribe RFC 9110]:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since
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.

RFC 2822 should not be recommended for handling HTTP requests
1 participant