1
+ [
2
+ ( ) => new Request ( "about:blank" , { headers : { "Content-Type" : "text/plain" } } ) ,
3
+ ( ) => new Response ( "" , { headers : { "Content-Type" : "text/plain" } } )
4
+ ] . forEach ( bodyContainerCreator => {
5
+ const bodyContainer = bodyContainerCreator ( ) ;
6
+ promise_test ( async t => {
7
+ assert_equals ( bodyContainer . headers . get ( "Content-Type" ) , "text/plain" ) ;
8
+ const newMIMEType = "test/test" ;
9
+ bodyContainer . headers . set ( "Content-Type" , newMIMEType ) ;
10
+ const blob = await bodyContainer . blob ( ) ;
11
+ assert_equals ( blob . type , newMIMEType ) ;
12
+ } , `${ bodyContainer . constructor . name } : overriding explicit Content-Type` ) ;
13
+ } ) ;
14
+
15
+ [
16
+ ( ) => new Request ( "about:blank" , { body : new URLSearchParams ( ) , method : "POST" } ) ,
17
+ ( ) => new Response ( new URLSearchParams ( ) ) ,
18
+ ] . forEach ( bodyContainerCreator => {
19
+ const bodyContainer = bodyContainerCreator ( ) ;
20
+ promise_test ( async t => {
21
+ assert_equals ( bodyContainer . headers . get ( "Content-Type" ) , "application/x-www-form-urlencoded;charset=UTF-8" ) ;
22
+ bodyContainer . headers . delete ( "Content-Type" ) ;
23
+ const blob = await bodyContainer . blob ( ) ;
24
+ assert_equals ( blob . type , "" ) ;
25
+ } , `${ bodyContainer . constructor . name } : removing implicit Content-Type` ) ;
26
+ } ) ;
27
+
28
+ [
29
+ ( ) => new Request ( "about:blank" , { body : new ArrayBuffer ( ) , method : "POST" } ) ,
30
+ ( ) => new Response ( new ArrayBuffer ( ) ) ,
31
+ ] . forEach ( bodyContainerCreator => {
32
+ const bodyContainer = bodyContainerCreator ( ) ;
33
+ promise_test ( async t => {
34
+ assert_equals ( bodyContainer . headers . get ( "Content-Type" ) , null ) ;
35
+ const newMIMEType = "test/test" ;
36
+ bodyContainer . headers . set ( "Content-Type" , newMIMEType ) ;
37
+ const blob = await bodyContainer . blob ( ) ;
38
+ assert_equals ( blob . type , newMIMEType ) ;
39
+ } , `${ bodyContainer . constructor . name } : setting missing Content-Type` ) ;
40
+ } ) ;
0 commit comments