A new RFC was released for Structured Fields: RFC9651.
What is it?
HTTP headers have been a bit of a free-for all in terms of how complex values
are encoded, with many headers requiring their own mini-parser.
A while back an effort was started to fix this for headers going forward, named 'Structured Fields'. They're called Fields and not 'Headers' because HTTP has both Headers and Trailers!
Structured fields let you encode things like lists, dictionaries, strings, numbers, booleans and binary data. The original RFC from 2021 is pretty successful and although many existing headers can't be retrofitted to this format, a lot of new standards are taking advantage.
Some examples:
// Parsed an ASCII string Header: "foo" // A simple string, called a 'Token' in the spec Header: foo // Parsed as number Header: 5 Header: -10 Header: 5.01415 // Parsed into boolean Header: ?1 Header: ?0 // Binaries are base64 encoded Header: :RE0gbWUgZm9yIGEgZnJlZSBjb29raWU=: // Items can have parameters Header: "Hello world"; a="5" // A simple list Header: 5, "foo", bar, ?1 # Each element can have parameters Header: sometoken; param1; param2=hi, 42 // A list can also contain lists itself. These are called 'inner lists' and // use parenthesis Header: sometoken, (innerlistitem1 innerlistitem2), (anotherlist) // A simple dictionary Header: fn="evert", ln="pot", coffee=?1 // Each item may have parameters too Header: foo=123; q=1, bar=123, q=0.5 // A dictionary value may be an inner list again Header: foo=(1 2 3)
The new RFC published last week adds 2 new data types: Dates and
'Display strings', which is a Unicode serialization that fits in the HTTP header (and trailer) format.
// Parsed into a Date object<br> Header: @1686634251 <p>// A Unicode string, called a 'Display String' in the spec. They use<br> // percent encoding, but encode a different set of characters than<br> // URLs.<br> Header %"Frysl%C3%A2n"<br> </p>
Why should you care?
If you encounter these headers in the wild, it's a really good idea to use a standard parser. One of the reasons is that with using structured-fields, there's a built-in extension mechanism. You'll want to make sure that when a new parameter appears your application doesn't suddenly break.
You may also want to define and use your own HTTP headers. The structured fields format is a very good 'default choice' that removes decisions such as 'How should I encode a key value object' or 'how do I encode a UTF-8 string'.
With parsers popping up for every language, you don't have to worry about writing your own one-off formats.
Javascript package
I'm the maintainer of a Javascript library for Structured Fields, called "structured headers", which I've also updated for this new RFC. I wish I picked the name "structured-fields", but I picked the name before the original standard changed it's name.
I've just released v2 of this library supporting these new types, and also added ES Modules support.
Comments?
Reply to one of these:
- [Mastodon post][4]
- [Bluesky post][5]
The above is the detailed content of New Structured Fields RFC out, and so is my Javascript package. For more information, please follow other related articles on the PHP Chinese website!

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools
