+2
CHANGELOG.md
+2
CHANGELOG.md
+9
-1
src/wisp.gleam
+9
-1
src/wisp.gleam
···
1165
1165
next: fn() -> Response,
1166
1166
) -> Response {
1167
1167
case list.key_find(request.headers, "content-type") {
1168
-
Ok(content_type) if content_type == expected -> next()
1168
+
Ok(content_type) ->
1169
+
// This header may have further such as `; charset=utf-8`, so discard
1170
+
// that if it exists.
1171
+
case string.split_once(content_type, ";") {
1172
+
Ok(#(content_type, _)) if content_type == expected -> next()
1173
+
_ if content_type == expected -> next()
1174
+
_ -> unsupported_media_type([expected])
1175
+
}
1176
+
1169
1177
_ -> unsupported_media_type([expected])
1170
1178
}
1171
1179
}
+10
test/wisp_test.gleam
+10
test/wisp_test.gleam
···
505
505
|> should.equal(wisp.ok())
506
506
}
507
507
508
+
pub fn require_content_type_charset_test() {
509
+
{
510
+
let request =
511
+
testing.get("/", [#("content-type", "text/plain; charset=utf-8")])
512
+
use <- wisp.require_content_type(request, "text/plain")
513
+
wisp.ok()
514
+
}
515
+
|> should.equal(wisp.ok())
516
+
}
517
+
508
518
pub fn require_content_type_missing_test() {
509
519
{
510
520
let request = testing.get("/", [])