Example #1
0
File: url.go Project: fwessels/mc
// guessURLContentType - guess content-type of the URL.
// on failure just return 'application/octet-stream'.
func guessURLContentType(urlStr string) string {
	url := client.NewURL(urlStr)
	extension := strings.TrimPrefix(filepath.Ext(url.Path), ".")
	contentType, e := contentdb.Lookup(extension)
	if e != nil {
		return "application/octet-stream"
	}
	return contentType
}
Example #2
0
func (s *MySuite) TestLookup(c *C) {
	// Test initializing.
	e := contentdb.Init()
	c.Assert(e, IsNil)

	// Test MustLookup.
	contentType, e := contentdb.Lookup("exe")
	c.Assert(e, IsNil)
	c.Assert(contentType, Not(Equals), "")

	// Test MustLookup.
	contentType = contentdb.MustLookup("exe")
	c.Assert(contentType, Not(Equals), "")
}