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
fbdbb595
Commit
fbdbb595
authored
Aug 26, 2011
by
Pascal S. de Kloe
Committed by
Russ Cox
Aug 26, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mime: media type formatter
R=bradfitz, rsc CC=golang-dev
https://golang.org/cl/4654069
parent
e753512e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
0 deletions
+53
-0
src/pkg/mime/grammar.go
src/pkg/mime/grammar.go
+9
-0
src/pkg/mime/mediatype.go
src/pkg/mime/mediatype.go
+44
-0
No files found.
src/pkg/mime/grammar.go
View file @
fbdbb595
...
...
@@ -22,6 +22,15 @@ func IsTokenChar(rune int) bool {
return
rune
>
0x20
&&
rune
<
0x7f
&&
!
isTSpecial
(
rune
)
}
// IsToken returns true if s is a 'token' as as defined by RFC 1521
// and RFC 2045.
func
IsToken
(
s
string
)
bool
{
if
s
==
""
{
return
false
}
return
strings
.
IndexFunc
(
s
,
isNotTokenChar
)
<
0
}
// IsQText returns true if rune is in 'qtext' as defined by RFC 822.
func
IsQText
(
rune
int
)
bool
{
// CHAR = <any ASCII character> ; ( 0-177, 0.-127.)
...
...
src/pkg/mime/mediatype.go
View file @
fbdbb595
...
...
@@ -12,6 +12,50 @@ import (
"unicode"
)
// FormatMediaType serializes type t, subtype sub and the paramaters
// param as a media type conform RFC 2045 and RFC 2616.
// The type, subtype, and parameter names are written in lower-case.
// When any of the arguments result in a standard violation then
// FormatMediaType returns the empty string.
func
FormatMediaType
(
t
,
sub
string
,
param
map
[
string
]
string
)
string
{
if
!
(
IsToken
(
t
)
&&
IsToken
(
sub
))
{
return
""
}
var
buffer
bytes
.
Buffer
buffer
.
WriteString
(
strings
.
ToLower
(
t
))
buffer
.
WriteByte
(
'/'
)
buffer
.
WriteString
(
strings
.
ToLower
(
sub
))
for
attribute
,
value
:=
range
param
{
buffer
.
WriteByte
(
';'
)
if
!
IsToken
(
attribute
)
{
return
""
}
buffer
.
WriteString
(
strings
.
ToLower
(
attribute
))
buffer
.
WriteByte
(
'='
)
if
IsToken
(
value
)
{
buffer
.
WriteString
(
value
)
continue
}
buffer
.
WriteByte
(
'"'
)
offset
:=
0
for
index
,
character
:=
range
value
{
if
character
==
'"'
||
character
==
'\r'
{
buffer
.
WriteString
(
value
[
offset
:
index
])
offset
=
index
buffer
.
WriteByte
(
'\\'
)
}
if
character
&
0x80
!=
0
{
return
""
}
}
buffer
.
WriteString
(
value
[
offset
:
])
buffer
.
WriteByte
(
'"'
)
}
return
buffer
.
String
()
}
func
checkMediaTypeDisposition
(
s
string
)
os
.
Error
{
typ
,
rest
:=
consumeToken
(
s
)
if
typ
==
""
{
...
...
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