@@ -33,6 +33,7 @@ pub const Mime = struct {
3333 pub const ContentTypeEnum = enum {
3434 text_xml ,
3535 text_html ,
36+ text_javascript ,
3637 text_plain ,
3738 unknown ,
3839 other ,
@@ -41,6 +42,7 @@ pub const Mime = struct {
4142 pub const ContentType = union (ContentTypeEnum ) {
4243 text_xml : void ,
4344 text_html : void ,
45+ text_javascript : void ,
4446 text_plain : void ,
4547 unknown : void ,
4648 other : struct { type : []const u8 , sub_type : []const u8 },
@@ -172,11 +174,17 @@ pub const Mime = struct {
172174 if (std .meta .stringToEnum (enum {
173175 @"text/xml" ,
174176 @"text/html" ,
177+
178+ @"text/javascript" ,
179+ @"application/javascript" ,
180+ @"application/x-javascript" ,
181+
175182 @"text/plain" ,
176183 }, type_name )) | known_type | {
177184 const ct : ContentType = switch (known_type ) {
178185 .@"text/xml" = > .{ .text_xml = {} },
179186 .@"text/html" = > .{ .text_html = {} },
187+ .@"text/javascript" , .@"application/javascript" , .@"application/x-javascript" = > .{ .text_javascript = {} },
180188 .@"text/plain" = > .{ .text_plain = {} },
181189 };
182190 return .{ ct , attribute_start };
@@ -337,22 +345,26 @@ test "Mime: parse common" {
337345 try expect (.{ .content_type = .{ .text_xml = {} } }, " TeXT/xml" );
338346 try expect (.{ .content_type = .{ .text_html = {} } }, "teXt/HtML ;" );
339347 try expect (.{ .content_type = .{ .text_plain = {} } }, "tExT/PlAiN;" );
348+
349+ try expect (.{ .content_type = .{ .text_javascript = {} } }, "text/javascript" );
350+ try expect (.{ .content_type = .{ .text_javascript = {} } }, "Application/JavaScript" );
351+ try expect (.{ .content_type = .{ .text_javascript = {} } }, "application/x-javascript" );
340352}
341353
342354test "Mime: parse uncommon" {
343355 defer testing .reset ();
344356
345- const text_javascript = Expectation {
346- .content_type = .{ .other = .{ .type = "text" , .sub_type = "javascript " } },
357+ const text_csv = Expectation {
358+ .content_type = .{ .other = .{ .type = "text" , .sub_type = "csv " } },
347359 };
348- try expect (text_javascript , "text/javascript " );
349- try expect (text_javascript , "text/javascript ;" );
350- try expect (text_javascript , " text/javascript \t " );
351- try expect (text_javascript , " text/javascript \t ;" );
360+ try expect (text_csv , "text/csv " );
361+ try expect (text_csv , "text/csv ;" );
362+ try expect (text_csv , " text/csv \t " );
363+ try expect (text_csv , " text/csv \t ;" );
352364
353365 try expect (
354- .{ .content_type = .{ .other = .{ .type = "text" , .sub_type = "javascript " } } },
355- "Text/Javascript " ,
366+ .{ .content_type = .{ .other = .{ .type = "text" , .sub_type = "csv " } } },
367+ "Text/CSV " ,
356368 );
357369}
358370
0 commit comments