Update VPA dependency github.com/emicklei/go-restful/v3

This commit is contained in:
Joachim Bartosik 2023-02-07 11:42:15 +01:00
parent d340085c3c
commit 80dfbf9f0a
13 changed files with 81 additions and 14 deletions

View File

@ -25,7 +25,7 @@ require (
github.com/blang/semver/v4 v4.0.0 // indirect github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/go-logr/logr v1.2.3 // indirect github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect

View File

@ -63,8 +63,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/emicklei/go-restful/v3 v3.8.0 h1:eCZ8ulSerjdAiaNpF7GxXIE7ZCMo1moN1qX+S609eVw= github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ=
github.com/emicklei/go-restful/v3 v3.8.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/emicklei/go-restful/v3 v3.10.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=

View File

@ -1,6 +1,21 @@
# Change history of go-restful # Change history of go-restful
## [v3.8.0] - 20221-06-06 ## [v3.10.1] - 2022-11-19
- fix broken 3.10.0 by using path package for joining paths
## [v3.10.0] - 2022-10-11 - BROKEN
- changed tokenizer to match std route match behavior; do not trimright the path (#511)
- Add MIME_ZIP (#512)
- Add MIME_ZIP and HEADER_ContentDisposition (#513)
- Changed how to get query parameter issue #510
## [v3.9.0] - 2022-07-21
- add support for http.Handler implementations to work as FilterFunction, issue #504 (thanks to https://github.com/ggicci)
## [v3.8.0] - 2022-06-06
- use exact matching of allowed domain entries, issue #489 (#493) - use exact matching of allowed domain entries, issue #489 (#493)
- this changes fixes [security] Authorization Bypass Through User-Controlled Key - this changes fixes [security] Authorization Bypass Through User-Controlled Key

View File

@ -84,6 +84,7 @@ func (u UserResource) findUser(request *restful.Request, response *restful.Respo
- Route errors produce HTTP 404/405/406/415 errors, customizable using ServiceErrorHandler(...) - Route errors produce HTTP 404/405/406/415 errors, customizable using ServiceErrorHandler(...)
- Configurable (trace) logging - Configurable (trace) logging
- Customizable gzip/deflate readers and writers using CompressorProvider registration - Customizable gzip/deflate readers and writers using CompressorProvider registration
- Inject your own http.Handler using the `HttpMiddlewareHandlerToFilter` function
## How to customize ## How to customize
There are several hooks to customize the behavior of the go-restful package. There are several hooks to customize the behavior of the go-restful package.
@ -94,7 +95,7 @@ There are several hooks to customize the behavior of the go-restful package.
- Trace logging - Trace logging
- Compression - Compression
- Encoders for other serializers - Encoders for other serializers
- Use [jsoniter](https://github.com/json-iterator/go) by build this package using a tag, e.g. `go build -tags=jsoniter .` - Use [jsoniter](https://github.com/json-iterator/go) by building this package using a build tag, e.g. `go build -tags=jsoniter .`
## Resources ## Resources

View File

@ -7,12 +7,14 @@ package restful
const ( const (
MIME_XML = "application/xml" // Accept or Content-Type used in Consumes() and/or Produces() MIME_XML = "application/xml" // Accept or Content-Type used in Consumes() and/or Produces()
MIME_JSON = "application/json" // Accept or Content-Type used in Consumes() and/or Produces() MIME_JSON = "application/json" // Accept or Content-Type used in Consumes() and/or Produces()
MIME_ZIP = "application/zip" // Accept or Content-Type used in Consumes() and/or Produces()
MIME_OCTET = "application/octet-stream" // If Content-Type is not present in request, use the default MIME_OCTET = "application/octet-stream" // If Content-Type is not present in request, use the default
HEADER_Allow = "Allow" HEADER_Allow = "Allow"
HEADER_Accept = "Accept" HEADER_Accept = "Accept"
HEADER_Origin = "Origin" HEADER_Origin = "Origin"
HEADER_ContentType = "Content-Type" HEADER_ContentType = "Content-Type"
HEADER_ContentDisposition = "Content-Disposition"
HEADER_LastModified = "Last-Modified" HEADER_LastModified = "Last-Modified"
HEADER_AcceptEncoding = "Accept-Encoding" HEADER_AcceptEncoding = "Accept-Encoding"
HEADER_ContentEncoding = "Content-Encoding" HEADER_ContentEncoding = "Content-Encoding"

View File

@ -0,0 +1,21 @@
package restful
import (
"net/http"
)
// HttpMiddlewareHandler is a function that takes a http.Handler and returns a http.Handler
type HttpMiddlewareHandler func(http.Handler) http.Handler
// HttpMiddlewareHandlerToFilter converts a HttpMiddlewareHandler to a FilterFunction.
func HttpMiddlewareHandlerToFilter(middleware HttpMiddlewareHandler) FilterFunction {
return func(req *Request, resp *Response, chain *FilterChain) {
next := http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
req.Request = r
resp.ResponseWriter = rw
chain.ProcessFilter(req, resp)
})
middleware(next).ServeHTTP(resp.ResponseWriter, req.Request)
}
}

View File

@ -22,6 +22,9 @@ const (
// FormParameterKind = indicator of Request parameter type "form" // FormParameterKind = indicator of Request parameter type "form"
FormParameterKind FormParameterKind
// MultiPartFormParameterKind = indicator of Request parameter type "multipart/form-data"
MultiPartFormParameterKind
// CollectionFormatCSV comma separated values `foo,bar` // CollectionFormatCSV comma separated values `foo,bar`
CollectionFormatCSV = CollectionFormat("csv") CollectionFormatCSV = CollectionFormat("csv")
@ -108,6 +111,11 @@ func (p *Parameter) beForm() *Parameter {
return p return p
} }
func (p *Parameter) beMultiPartForm() *Parameter {
p.data.Kind = MultiPartFormParameterKind
return p
}
// Required sets the required field and returns the receiver // Required sets the required field and returns the receiver
func (p *Parameter) Required(required bool) *Parameter { func (p *Parameter) Required(required bool) *Parameter {
p.data.Required = required p.data.Required = required

View File

@ -31,7 +31,8 @@ func NewRequest(httpRequest *http.Request) *Request {
// a "Unable to unmarshal content of type:" response is returned. // a "Unable to unmarshal content of type:" response is returned.
// Valid values are restful.MIME_JSON and restful.MIME_XML // Valid values are restful.MIME_JSON and restful.MIME_XML
// Example: // Example:
// restful.DefaultRequestContentType(restful.MIME_JSON) //
// restful.DefaultRequestContentType(restful.MIME_JSON)
func DefaultRequestContentType(mime string) { func DefaultRequestContentType(mime string) {
defaultRequestContentType = mime defaultRequestContentType = mime
} }
@ -48,7 +49,7 @@ func (r *Request) PathParameters() map[string]string {
// QueryParameter returns the (first) Query parameter value by its name // QueryParameter returns the (first) Query parameter value by its name
func (r *Request) QueryParameter(name string) string { func (r *Request) QueryParameter(name string) string {
return r.Request.FormValue(name) return r.Request.URL.Query().Get(name)
} }
// QueryParameters returns the all the query parameters values by name // QueryParameters returns the all the query parameters values by name

View File

@ -109,6 +109,9 @@ func (r *Response) EntityWriter() (EntityReaderWriter, bool) {
if DefaultResponseMimeType == MIME_XML { if DefaultResponseMimeType == MIME_XML {
return entityAccessRegistry.accessorAt(MIME_XML) return entityAccessRegistry.accessorAt(MIME_XML)
} }
if DefaultResponseMimeType == MIME_ZIP {
return entityAccessRegistry.accessorAt(MIME_ZIP)
}
// Fallback to whatever the route says it can produce. // Fallback to whatever the route says it can produce.
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html // https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
for _, each := range r.routeProduces { for _, each := range r.routeProduces {

View File

@ -164,7 +164,7 @@ func tokenizePath(path string) []string {
if "/" == path { if "/" == path {
return nil return nil
} }
return strings.Split(strings.Trim(path, "/"), "/") return strings.Split(strings.TrimLeft(path, "/"), "/")
} }
// for debugging // for debugging
@ -176,3 +176,5 @@ func (r *Route) String() string {
func (r *Route) EnableContentEncoding(enabled bool) { func (r *Route) EnableContentEncoding(enabled bool) {
r.contentEncodingEnabled = &enabled r.contentEncodingEnabled = &enabled
} }
var TrimRightSlashEnabled = false

View File

@ -7,6 +7,7 @@ package restful
import ( import (
"fmt" "fmt"
"os" "os"
"path"
"reflect" "reflect"
"runtime" "runtime"
"strings" "strings"
@ -46,11 +47,12 @@ type RouteBuilder struct {
// Do evaluates each argument with the RouteBuilder itself. // Do evaluates each argument with the RouteBuilder itself.
// This allows you to follow DRY principles without breaking the fluent programming style. // This allows you to follow DRY principles without breaking the fluent programming style.
// Example: // Example:
// ws.Route(ws.DELETE("/{name}").To(t.deletePerson).Do(Returns200, Returns500))
// //
// func Returns500(b *RouteBuilder) { // ws.Route(ws.DELETE("/{name}").To(t.deletePerson).Do(Returns200, Returns500))
// b.Returns(500, "Internal Server Error", restful.ServiceError{}) //
// } // func Returns500(b *RouteBuilder) {
// b.Returns(500, "Internal Server Error", restful.ServiceError{})
// }
func (b *RouteBuilder) Do(oneArgBlocks ...func(*RouteBuilder)) *RouteBuilder { func (b *RouteBuilder) Do(oneArgBlocks ...func(*RouteBuilder)) *RouteBuilder {
for _, each := range oneArgBlocks { for _, each := range oneArgBlocks {
each(b) each(b)
@ -352,7 +354,7 @@ func (b *RouteBuilder) Build() Route {
} }
func concatPath(path1, path2 string) string { func concatPath(path1, path2 string) string {
return strings.TrimRight(path1, "/") + "/" + strings.TrimLeft(path2, "/") return path.Join(path1, path2)
} }
var anonymousFuncCount int32 var anonymousFuncCount int32

View File

@ -165,6 +165,18 @@ func FormParameter(name, description string) *Parameter {
return p return p
} }
// MultiPartFormParameter creates a new Parameter of kind Form (using multipart/form-data) for documentation purposes.
// It is initialized as required with string as its DataType.
func (w *WebService) MultiPartFormParameter(name, description string) *Parameter {
return MultiPartFormParameter(name, description)
}
func MultiPartFormParameter(name, description string) *Parameter {
p := &Parameter{&ParameterData{Name: name, Description: description, Required: false, DataType: "string"}}
p.beMultiPartForm()
return p
}
// Route creates a new Route using the RouteBuilder and add to the ordered list of Routes. // Route creates a new Route using the RouteBuilder and add to the ordered list of Routes.
func (w *WebService) Route(builder *RouteBuilder) *WebService { func (w *WebService) Route(builder *RouteBuilder) *WebService {
w.routesLock.Lock() w.routesLock.Lock()

View File

@ -16,7 +16,7 @@ github.com/cespare/xxhash/v2
# github.com/davecgh/go-spew v1.1.1 # github.com/davecgh/go-spew v1.1.1
## explicit ## explicit
github.com/davecgh/go-spew/spew github.com/davecgh/go-spew/spew
# github.com/emicklei/go-restful/v3 v3.8.0 # github.com/emicklei/go-restful/v3 v3.10.1
## explicit; go 1.13 ## explicit; go 1.13
github.com/emicklei/go-restful/v3 github.com/emicklei/go-restful/v3
github.com/emicklei/go-restful/v3/log github.com/emicklei/go-restful/v3/log