type_windows.mx raw

   1  // Copyright 2010 The Go Authors. All rights reserved.
   2  // Use of this source code is governed by a BSD-style
   3  // license that can be found in the LICENSE file.
   4  
   5  package mime
   6  
   7  import (
   8  	"internal/syscall/windows/registry"
   9  )
  10  
  11  func init() {
  12  	osInitMime = initMimeWindows
  13  }
  14  
  15  func initMimeWindows() {
  16  	names, err := registry.CLASSES_ROOT.ReadSubKeyNames()
  17  	if err != nil {
  18  		return
  19  	}
  20  	for _, name := range names {
  21  		if len(name) < 2 || name[0] != '.' { // looking for extensions only
  22  			continue
  23  		}
  24  		k, err := registry.OpenKey(registry.CLASSES_ROOT, name, registry.READ)
  25  		if err != nil {
  26  			continue
  27  		}
  28  		v, _, err := k.GetStringValue("Content Type")
  29  		k.Close()
  30  		if err != nil {
  31  			continue
  32  		}
  33  
  34  		// There is a long-standing problem on Windows: the
  35  		// registry sometimes records that the ".js" extension
  36  		// should be "text/plain". See issue #32350. While
  37  		// normally local configuration should override
  38  		// defaults, this problem is common enough that we
  39  		// handle it here by ignoring that registry setting.
  40  		if name == ".js" && (v == "text/plain" || v == "text/plain; charset=utf-8") {
  41  			continue
  42  		}
  43  
  44  		setExtensionType(name, v)
  45  	}
  46  }
  47  
  48  func initMimeForTests() map[string][]byte {
  49  	return map[string][]byte{
  50  		".PnG": "image/png",
  51  	}
  52  }
  53