🧚 A practical web framework for Gleam

Handle attributes

+21 -1
+2
CHANGELOG.md
··· 4 5 - HTML and JSON body functions now include `charset=utf-8` in the content-type 6 header. 7 8 ## v0.15.0 - 2024-05-12 9
··· 4 5 - HTML and JSON body functions now include `charset=utf-8` in the content-type 6 header. 7 + - The `require_content_type` function now handles additional attributes 8 + correctly. 9 10 ## v0.15.0 - 2024-05-12 11
+9 -1
src/wisp.gleam
··· 1165 next: fn() -> Response, 1166 ) -> Response { 1167 case list.key_find(request.headers, "content-type") { 1168 - Ok(content_type) if content_type == expected -> next() 1169 _ -> unsupported_media_type([expected]) 1170 } 1171 }
··· 1165 next: fn() -> Response, 1166 ) -> Response { 1167 case list.key_find(request.headers, "content-type") { 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 + 1177 _ -> unsupported_media_type([expected]) 1178 } 1179 }
+10
test/wisp_test.gleam
··· 505 |> should.equal(wisp.ok()) 506 } 507 508 pub fn require_content_type_missing_test() { 509 { 510 let request = testing.get("/", [])
··· 505 |> should.equal(wisp.ok()) 506 } 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 + 518 pub fn require_content_type_missing_test() { 519 { 520 let request = testing.get("/", [])