🧚 A practical web framework for Gleam

Handle attributes

Changed files
+21 -1
src
test
+2
CHANGELOG.md
··· 4 4 5 5 - HTML and JSON body functions now include `charset=utf-8` in the content-type 6 6 header. 7 + - The `require_content_type` function now handles additional attributes 8 + correctly. 7 9 8 10 ## v0.15.0 - 2024-05-12 9 11
+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
··· 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("/", [])