Skip to content

Commit

Permalink
✨ feat: add support for parameters in content negotiation
Browse files Browse the repository at this point in the history
Attempts to approach the level of support offered by express,
but behavior may differ in unusual corner cases.
Some key behaviors from Express that are implemented:
 - If an offer does not have every parameter listed in the given Accept,
   it is rejected.
 - Parameters do not affect specificity.
 - In a given specificity, more parameters gives greater precedence
 - Parameters are unordered
 - Matching is case-insensitive
 - Surrounding quotes behave strangely (buggy?) in Express, so we only
   explicitly handle what RFC-9110 allows, which is a quoted value
   (right side of the equal sign)

Behaviors were mostly reverse engineered from res.format in Express.

https://www.rfc-editor.org/rfc/rfc9110#name-parameters
  • Loading branch information
nickajacks1 committed Oct 22, 2023
1 parent cb89cce commit 85c131e
Show file tree
Hide file tree
Showing 4 changed files with 512 additions and 82 deletions.
2 changes: 1 addition & 1 deletion ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (c *Ctx) Body() []byte {

// Split and get the encodings list, in order to attend the
// rule defined at: https://www.rfc-editor.org/rfc/rfc9110#section-8.4-5
encodingOrder = getSplicedStrList(headerEncoding, encodingOrder)
encodingOrder = getSplicedStrList(headerEncoding, encodingOrder, ',')
if len(encodingOrder) == 0 {
return c.fasthttp.Request.Body()
}
Expand Down
Loading

0 comments on commit 85c131e

Please sign in to comment.