Commit 91643acc authored by Russ Cox's avatar Russ Cox

mime: fix build

The fix is to add ' ' after ';' so that we match
what we used to generate.
Packages like http look for the string with
the space in it, and I don't see a reason to
be so terse.

Also s/buffer/b/

TBR=bradfitz
CC=golang-dev
https://golang.org/cl/4959044
parent 75199664
......@@ -21,39 +21,40 @@ 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))
var b bytes.Buffer
b.WriteString(strings.ToLower(t))
b.WriteByte('/')
b.WriteString(strings.ToLower(sub))
for attribute, value := range param {
buffer.WriteByte(';')
b.WriteByte(';')
b.WriteByte(' ')
if !IsToken(attribute) {
return ""
}
buffer.WriteString(strings.ToLower(attribute))
buffer.WriteByte('=')
b.WriteString(strings.ToLower(attribute))
b.WriteByte('=')
if IsToken(value) {
buffer.WriteString(value)
b.WriteString(value)
continue
}
buffer.WriteByte('"')
b.WriteByte('"')
offset := 0
for index, character := range value {
if character == '"' || character == '\r' {
buffer.WriteString(value[offset:index])
b.WriteString(value[offset:index])
offset = index
buffer.WriteByte('\\')
b.WriteByte('\\')
}
if character&0x80 != 0 {
return ""
}
}
buffer.WriteString(value[offset:])
buffer.WriteByte('"')
b.WriteString(value[offset:])
b.WriteByte('"')
}
return buffer.String()
return b.String()
}
func checkMediaTypeDisposition(s string) os.Error {
......
......@@ -20,15 +20,15 @@ var typeFiles = []string{
}
var mimeTypes = map[string]string{
".css": "text/css;charset=utf-8",
".css": "text/css; charset=utf-8",
".gif": "image/gif",
".htm": "text/html;charset=utf-8",
".html": "text/html;charset=utf-8",
".htm": "text/html; charset=utf-8",
".html": "text/html; charset=utf-8",
".jpg": "image/jpeg",
".js": "application/x-javascript",
".pdf": "application/pdf",
".png": "image/png",
".xml": "text/xml;charset=utf-8",
".xml": "text/xml; charset=utf-8",
}
var mimeLock sync.RWMutex
......
......@@ -8,7 +8,7 @@ import "testing"
var typeTests = map[string]string{
".t1": "application/test",
".t2": "text/test;charset=utf-8",
".t2": "text/test; charset=utf-8",
".png": "image/png",
}
......@@ -25,7 +25,7 @@ func TestTypeByExtension(t *testing.T) {
}
func TestCustomExtension(t *testing.T) {
custom := "text/xml;charset=iso-8859-1"
custom := "text/xml; charset=iso-8859-1"
if error := AddExtensionType(".xml", custom); error != nil {
t.Fatalf("error %s for AddExtension(%s)", error, custom)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment