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

natively support Structured Field Values #2654

Open
Jxck opened this issue May 10, 2024 · 1 comment
Open

natively support Structured Field Values #2654

Jxck opened this issue May 10, 2024 · 1 comment
Labels
enhancement New feature or request.

Comments

@Jxck
Copy link
Contributor

Jxck commented May 10, 2024

What is the feature you are proposing?

Structured Field Values is the standard spec for serialize structured object into http header value.

It already referrered by tons of newly defined http specs.

And also, IETF HTTP Working Group currently working on retrofit SFV with existing headers.

So we can say it's a best practice to use SFV for headers, not JSON in any headers.
For avoiding developer using JSON or any other format, or SFV like format via hand-made-string-concat, Hono can natively support SFV encoder/decoder and guide developer to use it.

for example.

c.res.headers.append('Cache-Status', 'OriginCache; hit; ttl=1100, "CDN Company Here"; hit; ttl=545')

can be type gurded, by require SFList for value when key is Cache-Status.

c.res.headers.append('Cache-Status',  sfv.encodeList([{
  "value": "Symbol(OriginCache)",
  "params": {
   "hit": true,
   "ttl": 1100
  }
 },
 {
  "value": "CDN Company Here",
  "params": {
   "hit": true,
   "ttl": 545
  }
 }
]))

FYI: I published typed SFV library to npm https://github.com/jxck/structured-field-values

Thanks.

@Jxck Jxck added the enhancement New feature or request. label May 10, 2024
@yusukebe
Copy link
Member

Hi @Jxck !

It's very interesting, and your library seems very good. If we implement it, we will add the feature to c.header(). I'll try to investigate the SFV more. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

2 participants