@@ -49,6 +49,43 @@ describe('type()', () => {
49
49
expect ( type . boundary ) . to . equal ( 'abcdefghijklm' ) ;
50
50
} ) ;
51
51
52
+ it ( 'parses header (charset)' , ( ) => {
53
+
54
+ const type = Content . type ( 'application/json; charset=utf-8' ) ;
55
+ expect ( type . mime ) . to . equal ( 'application/json' ) ;
56
+ expect ( type . charset ) . to . equal ( 'utf-8' ) ;
57
+ } ) ;
58
+
59
+ it ( 'parses header (quoted charset)' , ( ) => {
60
+
61
+ const type = Content . type ( 'application/json; charset="iso-8859-1"' ) ;
62
+ expect ( type . mime ) . to . equal ( 'application/json' ) ;
63
+ expect ( type . charset ) . to . equal ( 'iso-8859-1' ) ;
64
+ } ) ;
65
+
66
+ it ( 'parses header (charset and boundary)' , ( ) => {
67
+
68
+ const type = Content . type ( 'multipart/form-data; charset=utf-8; boundary=abcdefghijklm' ) ;
69
+ expect ( type . mime ) . to . equal ( 'multipart/form-data' ) ;
70
+ expect ( type . charset ) . to . equal ( 'utf-8' ) ;
71
+ expect ( type . boundary ) . to . equal ( 'abcdefghijklm' ) ;
72
+ } ) ;
73
+
74
+ it ( 'parses header (boundary and charset)' , ( ) => {
75
+
76
+ const type = Content . type ( 'multipart/form-data; boundary=abcdefghijklm; charset=utf-8' ) ;
77
+ expect ( type . mime ) . to . equal ( 'multipart/form-data' ) ;
78
+ expect ( type . charset ) . to . equal ( 'utf-8' ) ;
79
+ expect ( type . boundary ) . to . equal ( 'abcdefghijklm' ) ;
80
+ } ) ;
81
+
82
+ it ( 'parses header (uppercase)' , ( ) => {
83
+
84
+ const type = Content . type ( 'TEXT/HTML; CHARSET=EUC-KR' ) ;
85
+ expect ( type . mime ) . to . equal ( 'text/html' ) ;
86
+ expect ( type . charset ) . to . equal ( 'euc-kr' ) ;
87
+ } ) ;
88
+
52
89
it ( 'handles large number of OWS' , ( ) => {
53
90
54
91
const now = Date . now ( ) ;
@@ -78,7 +115,15 @@ describe('type()', () => {
78
115
79
116
it ( 'handles multiple boundary params' , ( ) => {
80
117
81
- const header = '0/\\x00;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#;boundary=#"' ;
118
+ const header = `multipart/form-data ${ new Array ( 80000 ) . join ( ';boundary=#' ) } ` ;
119
+ const now = Date . now ( ) ;
120
+ Content . type ( header ) ;
121
+ expect ( Date . now ( ) - now ) . to . be . below ( 100 ) ;
122
+ } ) ;
123
+
124
+ it ( 'handles multiple charset params' , ( ) => {
125
+
126
+ const header = `text/plain ${ new Array ( 80000 ) . join ( ';charset=utf-8' ) } ` ;
82
127
const now = Date . now ( ) ;
83
128
Content . type ( header ) ;
84
129
expect ( Date . now ( ) - now ) . to . be . below ( 100 ) ;
0 commit comments