Acccess Content-Type via ContentType() accessor

This commit is contained in:
Aliaksandr Valialkin
2015-11-16 16:06:28 +02:00
parent 230a396384
commit e264d1a4f8
2 changed files with 15 additions and 15 deletions
+14 -14
View File
@@ -265,8 +265,8 @@ func (h *RequestHeader) CopyTo(dst *RequestHeader) {
// f must not retain references to key and/or value after returning.
// Copy key and/or value contents before returning if you need retaining them.
func (h *ResponseHeader) VisitAll(f func(key, value []byte)) {
if len(h.contentType) > 0 {
f(strContentType, h.contentType)
if len(h.ContentType()) > 0 {
f(strContentType, h.ContentType())
}
if len(h.server) > 0 {
f(strServer, h.server)
@@ -309,8 +309,8 @@ func (h *RequestHeader) VisitAll(f func(key, value []byte)) {
if len(h.host) > 0 {
f(strHost, h.host)
}
if len(h.contentType) > 0 {
f(strContentType, h.contentType)
if len(h.ContentType()) > 0 {
f(strContentType, h.ContentType())
}
if len(h.userAgent) > 0 {
f(strUserAgent, h.userAgent)
@@ -391,7 +391,7 @@ func (h *ResponseHeader) SetBytesKV(key, value []byte) {
func (h *ResponseHeader) SetCanonical(key, value []byte) {
switch {
case bytes.Equal(strContentType, key):
h.contentType = append(h.contentType[:0], value...)
h.SetContentTypeBytes(value)
case bytes.Equal(strServer, key):
h.server = append(h.server[:0], value...)
case bytes.Equal(strContentLength, key):
@@ -485,7 +485,7 @@ func (h *RequestHeader) SetCanonical(key, value []byte) {
case bytes.Equal(strHost, key):
h.host = append(h.host[:0], value...)
case bytes.Equal(strContentType, key):
h.contentType = append(h.contentType[:0], value...)
h.SetContentTypeBytes(value)
case bytes.Equal(strUserAgent, key):
h.userAgent = append(h.userAgent[:0], value...)
case bytes.Equal(strContentLength, key):
@@ -548,7 +548,7 @@ func (h *RequestHeader) PeekBytes(key []byte) []byte {
func (h *ResponseHeader) peek(key []byte) []byte {
switch {
case bytes.Equal(strContentType, key):
return h.contentType
return h.ContentType()
case bytes.Equal(strServer, key):
return h.server
case bytes.Equal(strConnection, key):
@@ -566,7 +566,7 @@ func (h *RequestHeader) peek(key []byte) []byte {
case bytes.Equal(strHost, key):
return h.host
case bytes.Equal(strContentType, key):
return h.contentType
return h.ContentType()
case bytes.Equal(strUserAgent, key):
return h.userAgent
case bytes.Equal(strConnection, key):
@@ -718,7 +718,7 @@ func (h *ResponseHeader) Write(w *bufio.Writer) error {
writeHeaderLine(w, strServer, server)
writeHeaderLine(w, strDate, serverDate.Load().([]byte))
contentType := h.contentType
contentType := h.ContentType()
if len(contentType) == 0 {
contentType = defaultContentType
}
@@ -782,7 +782,7 @@ func (h *RequestHeader) Write(w *bufio.Writer) error {
writeHeaderLine(w, strHost, host)
if h.IsPost() {
contentType := h.contentType
contentType := h.ContentType()
if len(contentType) == 0 {
return fmt.Errorf("missing required Content-Type header for POST request")
}
@@ -919,7 +919,7 @@ func (h *ResponseHeader) parseHeaders(buf []byte) ([]byte, error) {
for s.next() {
switch {
case bytes.Equal(s.key, strContentType):
h.contentType = append(h.contentType[:0], s.value...)
h.SetContentTypeBytes(s.value)
case bytes.Equal(s.key, strServer):
h.server = append(h.server[:0], s.value...)
case bytes.Equal(s.key, strContentLength):
@@ -954,7 +954,7 @@ func (h *ResponseHeader) parseHeaders(buf []byte) ([]byte, error) {
return nil, s.err
}
if len(h.contentType) == 0 {
if len(h.ContentType()) == 0 {
return nil, fmt.Errorf("missing required Content-Type header in %q", buf)
}
if h.ContentLength == -2 {
@@ -978,7 +978,7 @@ func (h *RequestHeader) parseHeaders(buf []byte) ([]byte, error) {
case bytes.Equal(s.key, strUserAgent):
h.userAgent = append(h.userAgent[:0], s.value...)
case bytes.Equal(s.key, strContentType):
h.contentType = append(h.contentType[:0], s.value...)
h.SetContentTypeBytes(s.value)
case bytes.Equal(s.key, strContentLength):
if h.ContentLength != -1 {
h.ContentLength, err = parseContentLength(s.value)
@@ -1011,7 +1011,7 @@ func (h *RequestHeader) parseHeaders(buf []byte) ([]byte, error) {
return nil, fmt.Errorf("missing required Host header in %q", buf)
}
if h.IsPost() {
if len(h.contentType) == 0 {
if len(h.ContentType()) == 0 {
return nil, fmt.Errorf("missing Content-Type for POST header in %q", buf)
}
if h.ContentLength == -2 {
+1 -1
View File
@@ -125,7 +125,7 @@ func (req *Request) parsePostArgs() {
if !req.Header.IsPost() {
return
}
if !bytes.Equal(req.Header.contentType, strPostArgsContentType) {
if !bytes.Equal(req.Header.ContentType(), strPostArgsContentType) {
return
}
req.postArgs.ParseBytes(req.Body)