aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/emicklei/go-restful/request.go
diff options
context:
space:
mode:
authorGravatar Yong Tang <yong.tang.github@outlook.com> 2017-11-03 00:20:15 -0700
committerGravatar Miek Gieben <miek@miek.nl> 2017-11-03 07:20:15 +0000
commit1fc0c16968304b169fb7eb52f162ffa4c7cdc55c (patch)
treee242db88ffc7aa291a6344d1ab1d6cd07293cba7 /vendor/github.com/emicklei/go-restful/request.go
parentaf6086d6535e3309e3bd1e521cb4d51ef113f850 (diff)
downloadcoredns-1fc0c16968304b169fb7eb52f162ffa4c7cdc55c.tar.gz
coredns-1fc0c16968304b169fb7eb52f162ffa4c7cdc55c.tar.zst
coredns-1fc0c16968304b169fb7eb52f162ffa4c7cdc55c.zip
Update vendor libraries except client-go, apimachinery and ugorji/go (#1197)
This fix updates vendor libraries except client-go, apimachinery and ugorji/go, as github.com/ugorji/go/codec is causing compatibilities issues. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Diffstat (limited to 'vendor/github.com/emicklei/go-restful/request.go')
-rw-r--r--vendor/github.com/emicklei/go-restful/request.go34
1 files changed, 8 insertions, 26 deletions
diff --git a/vendor/github.com/emicklei/go-restful/request.go b/vendor/github.com/emicklei/go-restful/request.go
index 988adc984..8c23af12c 100644
--- a/vendor/github.com/emicklei/go-restful/request.go
+++ b/vendor/github.com/emicklei/go-restful/request.go
@@ -5,20 +5,15 @@ package restful
// that can be found in the LICENSE file.
import (
- "bytes"
"compress/zlib"
- "io/ioutil"
"net/http"
)
var defaultRequestContentType string
-var doCacheReadEntityBytes = true
-
// Request is a wrapper for a http Request that provides convenience methods
type Request struct {
Request *http.Request
- bodyContent *[]byte // to cache the request body for multiple reads of ReadEntity
pathParameters map[string]string
attributes map[string]interface{} // for storing request-scoped values
selectedRoutePath string // root path + route path that matched the request, e.g. /meetings/{id}/attendees
@@ -41,12 +36,6 @@ func DefaultRequestContentType(mime string) {
defaultRequestContentType = mime
}
-// SetCacheReadEntity controls whether the response data ([]byte) is cached such that ReadEntity is repeatable.
-// Default is true (due to backwardcompatibility). For better performance, you should set it to false if you don't need it.
-func SetCacheReadEntity(doCache bool) {
- doCacheReadEntityBytes = doCache
-}
-
// PathParameter accesses the Path parameter value by its name
func (r *Request) PathParameter(name string) string {
return r.pathParameters[name]
@@ -81,18 +70,6 @@ func (r *Request) ReadEntity(entityPointer interface{}) (err error) {
contentType := r.Request.Header.Get(HEADER_ContentType)
contentEncoding := r.Request.Header.Get(HEADER_ContentEncoding)
- // OLD feature, cache the body for reads
- if doCacheReadEntityBytes {
- if r.bodyContent == nil {
- data, err := ioutil.ReadAll(r.Request.Body)
- if err != nil {
- return err
- }
- r.bodyContent = &data
- }
- r.Request.Body = ioutil.NopCloser(bytes.NewReader(*r.bodyContent))
- }
-
// check if the request body needs decompression
if ENCODING_GZIP == contentEncoding {
gzipReader := currentCompressorProvider.AcquireGzipReader()
@@ -107,10 +84,15 @@ func (r *Request) ReadEntity(entityPointer interface{}) (err error) {
r.Request.Body = zlibReader
}
- // lookup the EntityReader
- entityReader, ok := entityAccessRegistry.AccessorAt(contentType)
+ // lookup the EntityReader, use defaultRequestContentType if needed and provided
+ entityReader, ok := entityAccessRegistry.accessorAt(contentType)
if !ok {
- return NewError(http.StatusBadRequest, "Unable to unmarshal content of type:"+contentType)
+ if len(defaultRequestContentType) != 0 {
+ entityReader, ok = entityAccessRegistry.accessorAt(defaultRequestContentType)
+ }
+ if !ok {
+ return NewError(http.StatusBadRequest, "Unable to unmarshal content of type:"+contentType)
+ }
}
return entityReader.Read(r, entityPointer)
}