]> Cypherpunks repositories - gostls13.git/commitdiff
mime: ignore .js => text/plain in Windows registry
authorIan Lance Taylor <iant@golang.org>
Tue, 17 May 2022 19:28:28 +0000 (12:28 -0700)
committerIan Lance Taylor <iant@golang.org>
Sat, 28 May 2022 20:07:28 +0000 (20:07 +0000)
This seems to be a common registry misconfiguration on Windows.

Fixes #32350

Change-Id: I68c617c42a6e72948e2acdf335ff8e7df569432d
Reviewed-on: https://go-review.googlesource.com/c/go/+/406894
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
doc/go1.19.html
src/mime/type_windows.go

index a83a916c725d393dfcf19ba30edb4a84a1d6f48e..c809e105515ee32a7381c63521c38f96179c2155 100644 (file)
@@ -216,6 +216,22 @@ Do not send CLs removing the interior tags from such phrases.
   </dd>
 </dl><!-- io -->
 
+<dl id="mime"><dt><a href="/pkg/mime/">mime</a></dt>
+  <dd>
+    <p><!-- CL 406894 -->
+      On Windows only, the mime package now ignores a registry entry
+      recording that the extension <code>.js</code> should have MIME
+      type <code>text/plain</code>. This is a common unintentional
+      misconfiguration on Windows systems. The effect is
+      that <code>.js</code> will have the default MIME
+      type <code>text/javascript; charset=utf-8</code>.
+      Applications that expect <code>text/plain</code> on Windows must
+      now explicitly call
+      <a href="/pkg/mime#AddExtensionType"><code>AddExtensionType</code></a>.
+    </p>
+  </dd>
+</dl>
+
 <dl id="net"><dt><a href="/pkg/net/">net</a></dt>
   <dd>
     <p><!-- CL 386016 -->
index cee9c9db041b2beff5e0820698cf2484de20e0cb..93802141c532d0f79daeecd356d022a89cbd6167 100644 (file)
@@ -30,6 +30,17 @@ func initMimeWindows() {
                if err != nil {
                        continue
                }
+
+               // There is a long-standing problem on Windows: the
+               // registry sometimes records that the ".js" extension
+               // should be "text/plain". See issue #32350. While
+               // normally local configuration should override
+               // defaults, this problem is common enough that we
+               // handle it here by ignoring that registry setting.
+               if name == ".js" && (v == "text/plain" || v == "text/plain; charset=utf-8") {
+                       continue
+               }
+
                setExtensionType(name, v)
        }
 }