@@ -49,6 +49,37 @@ app.Get("/", func(c *fiber.Ctx) error {
49
49
})
50
50
```
51
51
52
+ Media-Type parameters are supported.
53
+
54
+ ``` go title="Example 3"
55
+ // Accept: text/plain, application/json; version=1; foo=bar
56
+
57
+ app.Get (" /" , func (c *fiber.Ctx ) error {
58
+ // Extra parameters in the accept are ignored
59
+ c.Accepts (" text/plain;format=flowed" ) // "text/plain;format=flowed"
60
+
61
+ // An offer must contain all parameters present in the Accept type
62
+ c.Accepts (" application/json" ) // ""
63
+
64
+ // Parameter order and capitalization does not matter. Quotes on values are stripped.
65
+ c.Accepts (` application/json;foo="bar";VERSION=1` ) // "application/json;foo="bar";VERSION=1"
66
+ })
67
+ ```
68
+
69
+ ``` go title="Example 4"
70
+ // Accept: text/plain;format=flowed;q=0.9, text/plain
71
+ // i.e., "I prefer text/plain;format=flowed less than other forms of text/plain"
72
+ app.Get (" /" , func (c *fiber.Ctx ) error {
73
+ // Beware: the order in which offers are listed matters.
74
+ // Although the client specified they prefer not to receive format=flowed,
75
+ // the text/plain Accept matches with "text/plain;format=flowed" first, so it is returned.
76
+ c.Accepts (" text/plain;format=flowed" , " text/plain" ) // "text/plain;format=flowed"
77
+
78
+ // Here, things behave as expected:
79
+ c.Accepts (" text/plain" , " text/plain;format=flowed" ) // "text/plain"
80
+ })
81
+ ```
82
+
52
83
Fiber provides similar functions for the other accept headers.
53
84
54
85
``` go
0 commit comments