Fossil SCM

Added mjs (ES6 modules) mimetype. Changed JS mimetype from application/javascript to text/javascript to conform with the HTML spec. application/javascript is commonly used in the wild.

stephan 2022-06-08 10:08 pikchrshow-wasm
Commit a54a2c6ac3d7850b1373ee62fb3a245e79964701dbebe8241052ba6d537b4d7f
+4 -5
--- src/builtin.c
+++ src/builtin.c
@@ -130,20 +130,19 @@
130130
blob_reset(&x);
131131
}
132132
133133
/*
134134
** Input zList is a list of numeric identifiers for files in
135
-** aBuiltinFiles[]. Return the concatenation of all of those
136
-** files using mimetype zType, or as application/javascript if
137
-** zType is 0.
135
+** aBuiltinFiles[]. Return the concatenation of all of those files
136
+** using mimetype zType, or as text/javascript if zType is 0.
138137
*/
139138
static void builtin_deliver_multiple_js_files(
140139
const char *zList, /* List of numeric identifiers */
141140
const char *zType /* Override mimetype */
142141
){
143142
Blob *pOut;
144
- if( zType==0 ) zType = "application/javascript";
143
+ if( zType==0 ) zType = "text/javascript";
145144
cgi_set_content_type(zType);
146145
pOut = cgi_output_blob();
147146
while( zList[0] ){
148147
int i = atoi(zList);
149148
if( i>0 && i<=count(aBuiltinFiles) ){
@@ -203,11 +202,11 @@
203202
@ File "%h(zName)" not found
204203
return;
205204
}
206205
if( zType==0 ){
207206
if( sqlite3_strglob("*.js", zName)==0 ){
208
- zType = "application/javascript";
207
+ zType = "text/javascript";
209208
}else{
210209
zType = mimetype_from_name(zName);
211210
}
212211
}
213212
cgi_set_content_type(zType);
214213
--- src/builtin.c
+++ src/builtin.c
@@ -130,20 +130,19 @@
130 blob_reset(&x);
131 }
132
133 /*
134 ** Input zList is a list of numeric identifiers for files in
135 ** aBuiltinFiles[]. Return the concatenation of all of those
136 ** files using mimetype zType, or as application/javascript if
137 ** zType is 0.
138 */
139 static void builtin_deliver_multiple_js_files(
140 const char *zList, /* List of numeric identifiers */
141 const char *zType /* Override mimetype */
142 ){
143 Blob *pOut;
144 if( zType==0 ) zType = "application/javascript";
145 cgi_set_content_type(zType);
146 pOut = cgi_output_blob();
147 while( zList[0] ){
148 int i = atoi(zList);
149 if( i>0 && i<=count(aBuiltinFiles) ){
@@ -203,11 +202,11 @@
203 @ File "%h(zName)" not found
204 return;
205 }
206 if( zType==0 ){
207 if( sqlite3_strglob("*.js", zName)==0 ){
208 zType = "application/javascript";
209 }else{
210 zType = mimetype_from_name(zName);
211 }
212 }
213 cgi_set_content_type(zType);
214
--- src/builtin.c
+++ src/builtin.c
@@ -130,20 +130,19 @@
130 blob_reset(&x);
131 }
132
133 /*
134 ** Input zList is a list of numeric identifiers for files in
135 ** aBuiltinFiles[]. Return the concatenation of all of those files
136 ** using mimetype zType, or as text/javascript if zType is 0.
 
137 */
138 static void builtin_deliver_multiple_js_files(
139 const char *zList, /* List of numeric identifiers */
140 const char *zType /* Override mimetype */
141 ){
142 Blob *pOut;
143 if( zType==0 ) zType = "text/javascript";
144 cgi_set_content_type(zType);
145 pOut = cgi_output_blob();
146 while( zList[0] ){
147 int i = atoi(zList);
148 if( i>0 && i<=count(aBuiltinFiles) ){
@@ -203,11 +202,11 @@
202 @ File "%h(zName)" not found
203 return;
204 }
205 if( zType==0 ){
206 if( sqlite3_strglob("*.js", zName)==0 ){
207 zType = "text/javascript";
208 }else{
209 zType = mimetype_from_name(zName);
210 }
211 }
212 cgi_set_content_type(zType);
213
+7 -1
--- src/doc.c
+++ src/doc.c
@@ -156,11 +156,16 @@
156156
{ "jad", 3, "text/vnd.sun.j2me.app-descriptor" },
157157
{ "jar", 3, "application/java-archive" },
158158
{ "jpe", 3, "image/jpeg" },
159159
{ "jpeg", 4, "image/jpeg" },
160160
{ "jpg", 3, "image/jpeg" },
161
- { "js", 2, "application/javascript" },
161
+ { "js", 2, "text/javascript" },
162
+ /* application/javascript is commonly used for JS, but the
163
+ ** spec says text/javascript is correct:
164
+ ** https://html.spec.whatwg.org/multipage/scripting.html
165
+ ** #scriptingLanguages:javascript-mime-type */
166
+ { "json", 4, "application/json" },
162167
{ "kar", 3, "audio/midi" },
163168
{ "latex", 5, "application/x-latex" },
164169
{ "lha", 3, "application/octet-stream" },
165170
{ "lsp", 3, "application/x-lisp" },
166171
{ "lzh", 3, "application/octet-stream" },
@@ -173,10 +178,11 @@
173178
{ "mesh", 4, "model/mesh" },
174179
{ "mid", 3, "audio/midi" },
175180
{ "midi", 4, "audio/midi" },
176181
{ "mif", 3, "application/x-mif" },
177182
{ "mime", 4, "www/mime" },
183
+ { "mjs", 3, "text/javascript" /*EM6 modules*/ },
178184
{ "mkd", 3, "text/x-markdown" },
179185
{ "mov", 3, "video/quicktime" },
180186
{ "movie", 5, "video/x-sgi-movie" },
181187
{ "mp2", 3, "audio/mpeg" },
182188
{ "mp3", 3, "audio/mpeg" },
183189
--- src/doc.c
+++ src/doc.c
@@ -156,11 +156,16 @@
156 { "jad", 3, "text/vnd.sun.j2me.app-descriptor" },
157 { "jar", 3, "application/java-archive" },
158 { "jpe", 3, "image/jpeg" },
159 { "jpeg", 4, "image/jpeg" },
160 { "jpg", 3, "image/jpeg" },
161 { "js", 2, "application/javascript" },
 
 
 
 
 
162 { "kar", 3, "audio/midi" },
163 { "latex", 5, "application/x-latex" },
164 { "lha", 3, "application/octet-stream" },
165 { "lsp", 3, "application/x-lisp" },
166 { "lzh", 3, "application/octet-stream" },
@@ -173,10 +178,11 @@
173 { "mesh", 4, "model/mesh" },
174 { "mid", 3, "audio/midi" },
175 { "midi", 4, "audio/midi" },
176 { "mif", 3, "application/x-mif" },
177 { "mime", 4, "www/mime" },
 
178 { "mkd", 3, "text/x-markdown" },
179 { "mov", 3, "video/quicktime" },
180 { "movie", 5, "video/x-sgi-movie" },
181 { "mp2", 3, "audio/mpeg" },
182 { "mp3", 3, "audio/mpeg" },
183
--- src/doc.c
+++ src/doc.c
@@ -156,11 +156,16 @@
156 { "jad", 3, "text/vnd.sun.j2me.app-descriptor" },
157 { "jar", 3, "application/java-archive" },
158 { "jpe", 3, "image/jpeg" },
159 { "jpeg", 4, "image/jpeg" },
160 { "jpg", 3, "image/jpeg" },
161 { "js", 2, "text/javascript" },
162 /* application/javascript is commonly used for JS, but the
163 ** spec says text/javascript is correct:
164 ** https://html.spec.whatwg.org/multipage/scripting.html
165 ** #scriptingLanguages:javascript-mime-type */
166 { "json", 4, "application/json" },
167 { "kar", 3, "audio/midi" },
168 { "latex", 5, "application/x-latex" },
169 { "lha", 3, "application/octet-stream" },
170 { "lsp", 3, "application/x-lisp" },
171 { "lzh", 3, "application/octet-stream" },
@@ -173,10 +178,11 @@
178 { "mesh", 4, "model/mesh" },
179 { "mid", 3, "audio/midi" },
180 { "midi", 4, "audio/midi" },
181 { "mif", 3, "application/x-mif" },
182 { "mime", 4, "www/mime" },
183 { "mjs", 3, "text/javascript" /*EM6 modules*/ },
184 { "mkd", 3, "text/x-markdown" },
185 { "mov", 3, "video/quicktime" },
186 { "movie", 5, "video/x-sgi-movie" },
187 { "mp2", 3, "audio/mpeg" },
188 { "mp3", 3, "audio/mpeg" },
189
+10 -8
--- src/json.c
+++ src/json.c
@@ -558,11 +558,11 @@
558558
/*
559559
** Guesses a RESPONSE Content-Type value based (primarily) on the
560560
** HTTP_ACCEPT header.
561561
**
562562
** It will try to figure out if the client can support
563
-** application/json or application/javascript, and will fall back to
563
+** application/json, text/javascript, and will fall back to
564564
** text/plain if it cannot figure out anything more specific.
565565
**
566566
** Returned memory is static and immutable, but if the environment
567567
** changes after calling this then subsequent calls to this function
568568
** might return different (also static/immutable) values.
@@ -573,12 +573,12 @@
573573
cset = PD("HTTP_ACCEPT_CHARSET",NULL);
574574
doUtf8 = ((NULL == cset) || (NULL!=strstr("utf-8",cset)))
575575
? 1 : 0;
576576
if( g.json.jsonp ){
577577
return doUtf8
578
- ? "application/javascript; charset=utf-8"
579
- : "application/javascript";
578
+ ? "text/javascript; charset=utf-8"
579
+ : "text/javascript";
580580
}else{
581581
/*
582582
Content-type
583583
584584
If the browser does not sent an ACCEPT for application/json
@@ -605,18 +605,19 @@
605605
606606
/*
607607
** Given a request CONTENT_TYPE value, this function returns true
608608
** if it is of a type which the JSON API can ostensibly read.
609609
**
610
- ** It accepts any of application/json, text/plain, or
611
- ** application/javascript. The former is preferred, but was not
612
- ** widespread when this API was initially built, so the latter forms
613
- ** are permitted as fallbacks.
610
+ ** It accepts any of application/json, text/plain,
611
+ ** application/javascript, or text/javascript. The former is
612
+ ** preferred, but was not widespread when this API was initially
613
+ ** built, so the latter forms are permitted as fallbacks.
614614
*/
615615
int json_can_consume_content_type(const char * zType){
616616
return fossil_strcmp(zType, "application/json")==0
617617
|| fossil_strcmp(zType,"text/plain")==0/*assume this MIGHT be JSON*/
618
+ || fossil_strcmp(zType,"text/javascript")==0
618619
|| fossil_strcmp(zType,"application/javascript")==0;
619620
}
620621
621622
/*
622623
** Sends pResponse to the output stream as the response object. This
@@ -627,18 +628,19 @@
627628
** In CLI mode pResponse is sent to stdout immediately. In HTTP
628629
** mode pResponse replaces any current CGI content but cgi_reply()
629630
** is not called to flush the output.
630631
**
631632
** If g.json.jsonp is not NULL then the content type is set to
632
-** application/javascript and the output is wrapped in a jsonp
633
+** text/javascript and the output is wrapped in a jsonp
633634
** wrapper.
634635
*/
635636
void json_send_response( cson_value const * pResponse ){
636637
assert( NULL != pResponse );
637638
if( g.isHTTP ){
638639
cgi_reset_content();
639640
if( g.json.jsonp ){
641
+ cgi_set_content_type("text/javascript");
640642
cgi_printf("%s(",g.json.jsonp);
641643
}
642644
cson_output( pResponse, cson_data_dest_cgi, NULL, &g.json.outOpt );
643645
if( g.json.jsonp ){
644646
cgi_append_content(")",1);
645647
--- src/json.c
+++ src/json.c
@@ -558,11 +558,11 @@
558 /*
559 ** Guesses a RESPONSE Content-Type value based (primarily) on the
560 ** HTTP_ACCEPT header.
561 **
562 ** It will try to figure out if the client can support
563 ** application/json or application/javascript, and will fall back to
564 ** text/plain if it cannot figure out anything more specific.
565 **
566 ** Returned memory is static and immutable, but if the environment
567 ** changes after calling this then subsequent calls to this function
568 ** might return different (also static/immutable) values.
@@ -573,12 +573,12 @@
573 cset = PD("HTTP_ACCEPT_CHARSET",NULL);
574 doUtf8 = ((NULL == cset) || (NULL!=strstr("utf-8",cset)))
575 ? 1 : 0;
576 if( g.json.jsonp ){
577 return doUtf8
578 ? "application/javascript; charset=utf-8"
579 : "application/javascript";
580 }else{
581 /*
582 Content-type
583
584 If the browser does not sent an ACCEPT for application/json
@@ -605,18 +605,19 @@
605
606 /*
607 ** Given a request CONTENT_TYPE value, this function returns true
608 ** if it is of a type which the JSON API can ostensibly read.
609 **
610 ** It accepts any of application/json, text/plain, or
611 ** application/javascript. The former is preferred, but was not
612 ** widespread when this API was initially built, so the latter forms
613 ** are permitted as fallbacks.
614 */
615 int json_can_consume_content_type(const char * zType){
616 return fossil_strcmp(zType, "application/json")==0
617 || fossil_strcmp(zType,"text/plain")==0/*assume this MIGHT be JSON*/
 
618 || fossil_strcmp(zType,"application/javascript")==0;
619 }
620
621 /*
622 ** Sends pResponse to the output stream as the response object. This
@@ -627,18 +628,19 @@
627 ** In CLI mode pResponse is sent to stdout immediately. In HTTP
628 ** mode pResponse replaces any current CGI content but cgi_reply()
629 ** is not called to flush the output.
630 **
631 ** If g.json.jsonp is not NULL then the content type is set to
632 ** application/javascript and the output is wrapped in a jsonp
633 ** wrapper.
634 */
635 void json_send_response( cson_value const * pResponse ){
636 assert( NULL != pResponse );
637 if( g.isHTTP ){
638 cgi_reset_content();
639 if( g.json.jsonp ){
 
640 cgi_printf("%s(",g.json.jsonp);
641 }
642 cson_output( pResponse, cson_data_dest_cgi, NULL, &g.json.outOpt );
643 if( g.json.jsonp ){
644 cgi_append_content(")",1);
645
--- src/json.c
+++ src/json.c
@@ -558,11 +558,11 @@
558 /*
559 ** Guesses a RESPONSE Content-Type value based (primarily) on the
560 ** HTTP_ACCEPT header.
561 **
562 ** It will try to figure out if the client can support
563 ** application/json, text/javascript, and will fall back to
564 ** text/plain if it cannot figure out anything more specific.
565 **
566 ** Returned memory is static and immutable, but if the environment
567 ** changes after calling this then subsequent calls to this function
568 ** might return different (also static/immutable) values.
@@ -573,12 +573,12 @@
573 cset = PD("HTTP_ACCEPT_CHARSET",NULL);
574 doUtf8 = ((NULL == cset) || (NULL!=strstr("utf-8",cset)))
575 ? 1 : 0;
576 if( g.json.jsonp ){
577 return doUtf8
578 ? "text/javascript; charset=utf-8"
579 : "text/javascript";
580 }else{
581 /*
582 Content-type
583
584 If the browser does not sent an ACCEPT for application/json
@@ -605,18 +605,19 @@
605
606 /*
607 ** Given a request CONTENT_TYPE value, this function returns true
608 ** if it is of a type which the JSON API can ostensibly read.
609 **
610 ** It accepts any of application/json, text/plain,
611 ** application/javascript, or text/javascript. The former is
612 ** preferred, but was not widespread when this API was initially
613 ** built, so the latter forms are permitted as fallbacks.
614 */
615 int json_can_consume_content_type(const char * zType){
616 return fossil_strcmp(zType, "application/json")==0
617 || fossil_strcmp(zType,"text/plain")==0/*assume this MIGHT be JSON*/
618 || fossil_strcmp(zType,"text/javascript")==0
619 || fossil_strcmp(zType,"application/javascript")==0;
620 }
621
622 /*
623 ** Sends pResponse to the output stream as the response object. This
@@ -627,18 +628,19 @@
628 ** In CLI mode pResponse is sent to stdout immediately. In HTTP
629 ** mode pResponse replaces any current CGI content but cgi_reply()
630 ** is not called to flush the output.
631 **
632 ** If g.json.jsonp is not NULL then the content type is set to
633 ** text/javascript and the output is wrapped in a jsonp
634 ** wrapper.
635 */
636 void json_send_response( cson_value const * pResponse ){
637 assert( NULL != pResponse );
638 if( g.isHTTP ){
639 cgi_reset_content();
640 if( g.json.jsonp ){
641 cgi_set_content_type("text/javascript");
642 cgi_printf("%s(",g.json.jsonp);
643 }
644 cson_output( pResponse, cson_data_dest_cgi, NULL, &g.json.outOpt );
645 if( g.json.jsonp ){
646 cgi_append_content(")",1);
647
+2 -2
--- src/style.c
+++ src/style.c
@@ -901,11 +901,11 @@
901901
static void style_load_all_js_files(void){
902902
if( needHrefJs && g.perm.Hyperlink ){
903903
int nDelay = db_get_int("auto-hyperlink-delay",0);
904904
int bMouseover = db_get_boolean("auto-hyperlink-mouseover",0)
905905
&& sqlite3_strglob("*Android*",PD("HTTP_USER_AGENT",""));
906
- @ <script id='href-data' type='application/json'>\
906
+ @ <script id='href-data' type='text/json'>\
907907
@ {"delay":%d(nDelay),"mouseover":%d(bMouseover)}</script>
908908
}
909909
@ <script nonce="%h(style_nonce())">/* style.c:%d(__LINE__) */
910910
@ function debugMsg(msg){
911911
@ var n = document.getElementById("debugMsg");
@@ -1220,11 +1220,11 @@
12201220
/* Render the script as plain-text for testing purposes, if the "test"
12211221
** query parameter is present */
12221222
cgi_set_content_type("text/plain");
12231223
}else{
12241224
/* Default behavior is to return javascript */
1225
- cgi_set_content_type("application/javascript");
1225
+ cgi_set_content_type("text/javascript");
12261226
}
12271227
style_init_th1_vars(0);
12281228
Th_Render(zScript?zScript:"");
12291229
}
12301230
12311231
--- src/style.c
+++ src/style.c
@@ -901,11 +901,11 @@
901 static void style_load_all_js_files(void){
902 if( needHrefJs && g.perm.Hyperlink ){
903 int nDelay = db_get_int("auto-hyperlink-delay",0);
904 int bMouseover = db_get_boolean("auto-hyperlink-mouseover",0)
905 && sqlite3_strglob("*Android*",PD("HTTP_USER_AGENT",""));
906 @ <script id='href-data' type='application/json'>\
907 @ {"delay":%d(nDelay),"mouseover":%d(bMouseover)}</script>
908 }
909 @ <script nonce="%h(style_nonce())">/* style.c:%d(__LINE__) */
910 @ function debugMsg(msg){
911 @ var n = document.getElementById("debugMsg");
@@ -1220,11 +1220,11 @@
1220 /* Render the script as plain-text for testing purposes, if the "test"
1221 ** query parameter is present */
1222 cgi_set_content_type("text/plain");
1223 }else{
1224 /* Default behavior is to return javascript */
1225 cgi_set_content_type("application/javascript");
1226 }
1227 style_init_th1_vars(0);
1228 Th_Render(zScript?zScript:"");
1229 }
1230
1231
--- src/style.c
+++ src/style.c
@@ -901,11 +901,11 @@
901 static void style_load_all_js_files(void){
902 if( needHrefJs && g.perm.Hyperlink ){
903 int nDelay = db_get_int("auto-hyperlink-delay",0);
904 int bMouseover = db_get_boolean("auto-hyperlink-mouseover",0)
905 && sqlite3_strglob("*Android*",PD("HTTP_USER_AGENT",""));
906 @ <script id='href-data' type='text/json'>\
907 @ {"delay":%d(nDelay),"mouseover":%d(bMouseover)}</script>
908 }
909 @ <script nonce="%h(style_nonce())">/* style.c:%d(__LINE__) */
910 @ function debugMsg(msg){
911 @ var n = document.getElementById("debugMsg");
@@ -1220,11 +1220,11 @@
1220 /* Render the script as plain-text for testing purposes, if the "test"
1221 ** query parameter is present */
1222 cgi_set_content_type("text/plain");
1223 }else{
1224 /* Default behavior is to return javascript */
1225 cgi_set_content_type("text/javascript");
1226 }
1227 style_init_th1_vars(0);
1228 Th_Render(zScript?zScript:"");
1229 }
1230
1231

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button