Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
e527d49e
Commit
e527d49e
authored
Jul 26, 2011
by
David Symonds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: implement MP4 sniffing.
R=rsc CC=golang-dev
https://golang.org/cl/4809044
parent
003d5411
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletion
+30
-1
src/pkg/http/sniff.go
src/pkg/http/sniff.go
+28
-1
src/pkg/http/sniff_test.go
src/pkg/http/sniff_test.go
+2
-0
No files found.
src/pkg/http/sniff.go
View file @
e527d49e
...
...
@@ -6,6 +6,7 @@ package http
import
(
"bytes"
"encoding/binary"
)
// Content-type sniffing algorithm.
...
...
@@ -97,7 +98,7 @@ var sniffSignatures = []sniffSig{
&
exactSig
{[]
byte
(
"
\x50\x4B\x03\x04
"
),
"application/zip"
},
&
exactSig
{[]
byte
(
"
\x1F\x8B\x08
"
),
"application/x-gzip"
},
// TODO(dsymonds): MP4.
mp4Sig
(
0
),
textSig
(
0
),
// should be last
}
...
...
@@ -159,6 +160,32 @@ func (h htmlSig) match(data []byte, firstNonWS int) string {
return
"text/html; charset=utf-8"
}
type
mp4Sig
int
func
(
mp4Sig
)
match
(
data
[]
byte
,
firstNonWS
int
)
string
{
// c.f. section 6.1.
if
len
(
data
)
<
8
{
return
""
}
boxSize
:=
int
(
binary
.
BigEndian
.
Uint32
(
data
[
:
4
]))
if
boxSize
%
4
!=
0
||
len
(
data
)
<
boxSize
{
return
""
}
if
!
bytes
.
Equal
(
data
[
4
:
8
],
[]
byte
(
"ftyp"
))
{
return
""
}
for
st
:=
8
;
st
<
boxSize
;
st
+=
4
{
if
st
==
12
{
// minor version number
continue
}
if
bytes
.
Equal
(
data
[
st
:
st
+
3
],
[]
byte
(
"mp4"
))
{
return
"video/mp4"
}
}
return
""
}
type
textSig
int
func
(
textSig
)
match
(
data
[]
byte
,
firstNonWS
int
)
string
{
...
...
src/pkg/http/sniff_test.go
View file @
e527d49e
...
...
@@ -34,6 +34,8 @@ var sniffTests = []struct {
// Image types.
{
"GIF 87a"
,
[]
byte
(
`GIF87a`
),
"image/gif"
},
{
"GIF 89a"
,
[]
byte
(
`GIF89a...`
),
"image/gif"
},
{
"MP4"
,
[]
byte
(
"
\x00\x00\x00\x18
ftypmp42
\x00\x00\x00\x00
mp42isom<
\x06
t
\xbf
mdat"
),
"video/mp4"
},
}
func
TestDetectContentType
(
t
*
testing
.
T
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment