diff options
author | David Symonds <dsymonds@golang.org> | 2011-08-04 22:10:17 +1000 |
---|---|---|
committer | David Symonds <dsymonds@golang.org> | 2011-08-04 22:10:17 +1000 |
commit | 4143491c4ad17021b062c9fbabdc2d9d6aed11ef (patch) | |
tree | 21a241e86d5c33fe2bd77eb5f4238114eee2e096 | |
parent | 583f72434f5930bc40177bc9e3bca1a4ee027501 (diff) | |
download | go-4143491c4ad17021b062c9fbabdc2d9d6aed11ef.tar.gz go-4143491c4ad17021b062c9fbabdc2d9d6aed11ef.zip |
http: add more MPEG-4 MIME types to sniffer, and disable MP4 sniffing.
R=rsc
CC=golang-dev
https://golang.org/cl/4808056
-rw-r--r-- | src/pkg/http/sniff.go | 15 | ||||
-rw-r--r-- | src/pkg/http/sniff_test.go | 4 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/pkg/http/sniff.go b/src/pkg/http/sniff.go index 97b234e281..d608687507 100644 --- a/src/pkg/http/sniff.go +++ b/src/pkg/http/sniff.go @@ -98,7 +98,8 @@ var sniffSignatures = []sniffSig{ &exactSig{[]byte("\x50\x4B\x03\x04"), "application/zip"}, &exactSig{[]byte("\x1F\x8B\x08"), "application/x-gzip"}, - mp4Sig(0), + // TODO(dsymonds): Re-enable this when the spec is sorted w.r.t. MP4. + //mp4Sig(0), textSig(0), // should be last } @@ -179,8 +180,18 @@ func (mp4Sig) match(data []byte, firstNonWS int) string { // minor version number continue } - if bytes.Equal(data[st:st+3], []byte("mp4")) { + seg := string(data[st : st+3]) + switch seg { + case "mp4", "iso", "M4V", "M4P", "M4B": return "video/mp4" + /* The remainder are not in the spec. + case "M4A": + return "audio/mp4" + case "3gp": + return "video/3gpp" + case "jp2": + return "image/jp2" // JPEG 2000 + */ } } return "" diff --git a/src/pkg/http/sniff_test.go b/src/pkg/http/sniff_test.go index baf3a418b5..faf05e405a 100644 --- a/src/pkg/http/sniff_test.go +++ b/src/pkg/http/sniff_test.go @@ -35,7 +35,9 @@ var sniffTests = []struct { {"GIF 87a", []byte(`GIF87a`), "image/gif"}, {"GIF 89a", []byte(`GIF89a...`), "image/gif"}, - {"MP4", []byte("\x00\x00\x00\x18ftypmp42\x00\x00\x00\x00mp42isom<\x06t\xbfmdat"), "video/mp4"}, + // TODO(dsymonds): Re-enable this when the spec is sorted w.r.t. MP4. + //{"MP4 video", []byte("\x00\x00\x00\x18ftypmp42\x00\x00\x00\x00mp42isom<\x06t\xbfmdat"), "video/mp4"}, + //{"MP4 audio", []byte("\x00\x00\x00\x20ftypM4A \x00\x00\x00\x00M4A mp42isom\x00\x00\x00\x00"), "audio/mp4"}, } func TestDetectContentType(t *testing.T) { |