From 8703251d1fec7a013dfdadcaa78dea068e08c047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Michon?= Date: Mon, 23 Dec 2024 11:42:50 +0100 Subject: [PATCH] build(go.mod): update 'github.com/urfave/negroni' from v2 to v3 --- cmd/acadock-monitoring/main.go | 5 +- go.mod | 2 +- go.sum | 4 +- .../github.com/urfave/negroni/v2/.travis.yml | 30 ----- .../urfave/negroni/{v2 => v3}/.gitignore | 0 .../github.com/urfave/negroni/v3/.travis.yml | 56 +++++++++ .../urfave/negroni/{v2 => v3}/CHANGELOG.md | 40 ++++++- .../urfave/negroni/{v2 => v3}/LICENSE | 0 .../urfave/negroni/{v2 => v3}/README.md | 63 ++++++----- .../urfave/negroni/{v2 => v3}/doc.go | 0 .../urfave/negroni/{v2 => v3}/logger.go | 0 .../urfave/negroni/{v2 => v3}/negroni.go | 4 + .../urfave/negroni/{v2 => v3}/recovery.go | 0 .../negroni/{v2 => v3}/response_writer.go | 100 ++++++++-------- .../negroni/v3/response_writer_feature.go | 107 ++++++++++++++++++ .../{v2 => v3}/response_writer_pusher.go | 0 .../urfave/negroni/{v2 => v3}/static.go | 3 + vendor/modules.txt | 4 +- 18 files changed, 303 insertions(+), 115 deletions(-) delete mode 100644 vendor/github.com/urfave/negroni/v2/.travis.yml rename vendor/github.com/urfave/negroni/{v2 => v3}/.gitignore (100%) create mode 100644 vendor/github.com/urfave/negroni/v3/.travis.yml rename vendor/github.com/urfave/negroni/{v2 => v3}/CHANGELOG.md (76%) rename vendor/github.com/urfave/negroni/{v2 => v3}/LICENSE (100%) rename vendor/github.com/urfave/negroni/{v2 => v3}/README.md (64%) rename vendor/github.com/urfave/negroni/{v2 => v3}/doc.go (100%) rename vendor/github.com/urfave/negroni/{v2 => v3}/logger.go (100%) rename vendor/github.com/urfave/negroni/{v2 => v3}/negroni.go (99%) rename vendor/github.com/urfave/negroni/{v2 => v3}/recovery.go (100%) rename vendor/github.com/urfave/negroni/{v2 => v3}/response_writer.go (54%) create mode 100644 vendor/github.com/urfave/negroni/v3/response_writer_feature.go rename vendor/github.com/urfave/negroni/{v2 => v3}/response_writer_pusher.go (100%) rename vendor/github.com/urfave/negroni/{v2 => v3}/static.go (94%) diff --git a/cmd/acadock-monitoring/main.go b/cmd/acadock-monitoring/main.go index ad0523d1..0730e80c 100644 --- a/cmd/acadock-monitoring/main.go +++ b/cmd/acadock-monitoring/main.go @@ -9,7 +9,7 @@ import ( "os" "github.com/gorilla/mux" - "github.com/urfave/negroni/v2" + "github.com/urfave/negroni/v3" "github.com/Scalingo/acadock-monitoring/config" "github.com/Scalingo/acadock-monitoring/cpu" @@ -116,8 +116,7 @@ func main() { s := graceful.NewService() - err = s.ListenAndServe(ctx, "tcp", - ":"+config.ENV["PORT"], n) + err = s.ListenAndServe(ctx, "tcp", ":"+config.ENV["PORT"], n) if err != nil { log.WithError(err).Error("fail to stop http server") } diff --git a/go.mod b/go.mod index 311b25aa..508dc118 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.10.0 github.com/tklauser/go-sysconf v0.3.14 - github.com/urfave/negroni/v2 v2.0.2 + github.com/urfave/negroni/v3 v3.1.1 ) require ( diff --git a/go.sum b/go.sum index 208da760..70da4e20 100644 --- a/go.sum +++ b/go.sum @@ -102,8 +102,8 @@ github.com/tklauser/numcpus v0.9.0 h1:lmyCHtANi8aRUgkckBgoDk1nHCux3n2cgkJLXdQGPD github.com/tklauser/numcpus v0.9.0/go.mod h1:SN6Nq1O3VychhC1npsWostA+oW+VOQTxZrS604NSRyI= github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc= github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= -github.com/urfave/negroni/v2 v2.0.2 h1:27gJcVxYJ2a/ytEoCHoJ7ybvyhymV4cAhGuMxkyCsrU= -github.com/urfave/negroni/v2 v2.0.2/go.mod h1:SjdApKzYrObukpN/NnlejbQiZWIUjfDFzQltScGYigI= +github.com/urfave/negroni/v3 v3.1.1 h1:6MS4nG9Jk/UuCACaUlNXCbiKa0ywF9LXz5dGu09v8hw= +github.com/urfave/negroni/v3 v3.1.1/go.mod h1:jWvnX03kcSjDBl/ShB0iHvx5uOs7mAzZXW+JvJ5XYAs= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= diff --git a/vendor/github.com/urfave/negroni/v2/.travis.yml b/vendor/github.com/urfave/negroni/v2/.travis.yml deleted file mode 100644 index b6cb89fb..00000000 --- a/vendor/github.com/urfave/negroni/v2/.travis.yml +++ /dev/null @@ -1,30 +0,0 @@ -language: go - -sudo: false -dist: trusty - -go: -- 1.x -- 1.2.x -- 1.3.x -- 1.4.x -- 1.5.x -- 1.6.x -- 1.7.x -- 1.8.x -- 1.9.x -- 1.10.x -- 1.11.x -- master - -before_install: -- find "${GOPATH%%:*}" -name '*.a' -delete -- rm -rf "${GOPATH%%:*}/src/golang.org" -- go get golang.org/x/tools/cover -- go get golang.org/x/tools/cmd/cover - -script: -- go test -race -coverprofile=coverage.txt -covermode=atomic - -after_success: -- bash <(curl -s "https://codecov.io/bash") diff --git a/vendor/github.com/urfave/negroni/v2/.gitignore b/vendor/github.com/urfave/negroni/v3/.gitignore similarity index 100% rename from vendor/github.com/urfave/negroni/v2/.gitignore rename to vendor/github.com/urfave/negroni/v3/.gitignore diff --git a/vendor/github.com/urfave/negroni/v3/.travis.yml b/vendor/github.com/urfave/negroni/v3/.travis.yml new file mode 100644 index 00000000..4168bbf2 --- /dev/null +++ b/vendor/github.com/urfave/negroni/v3/.travis.yml @@ -0,0 +1,56 @@ +language: go + +sudo: false +dist: trusty +arch: + - AMD64 + - ppc64le + +go: +- 1.x +- 1.2.x +- 1.3.x +- 1.4.x +- 1.5.x +- 1.6.x +- 1.7.x +- 1.8.x +- 1.9.x +- 1.10.x +- 1.11.x +- master + +# Disable version 1.x, 1.2.x, 1.3.x, 1.4.x, 1.5.x, 1.6.x, 1.7.x, 1.8.x, 1.9.x, 1.10.x +jobs: + exclude: + - arch: ppc64le + go: 1.x + - arch: ppc64le + go: 1.2.x + - arch: ppc64le + go: 1.3.x + - arch: ppc64le + go: 1.4.x + - arch: ppc64le + go: 1.5.x + - arch: ppc64le + go: 1.6.x + - arch: ppc64le + go: 1.7.x + - arch: ppc64le + go: 1.8.x + - arch: ppc64le + go: 1.9.x + - arch: ppc64le + go: 1.10.x +before_install: +- find "${GOPATH%%:*}" -name '*.a' -delete +- rm -rf "${GOPATH%%:*}/src/golang.org" +- go get golang.org/x/tools/cover +- go get golang.org/x/tools/cmd/cover + +script: +- go test -race -coverprofile=coverage.txt -covermode=atomic + +after_success: +- bash <(curl -s "https://codecov.io/bash") diff --git a/vendor/github.com/urfave/negroni/v2/CHANGELOG.md b/vendor/github.com/urfave/negroni/v3/CHANGELOG.md similarity index 76% rename from vendor/github.com/urfave/negroni/v2/CHANGELOG.md rename to vendor/github.com/urfave/negroni/v3/CHANGELOG.md index de086f26..74cb729d 100644 --- a/vendor/github.com/urfave/negroni/v2/CHANGELOG.md +++ b/vendor/github.com/urfave/negroni/v3/CHANGELOG.md @@ -2,7 +2,45 @@ **ATTN**: This project uses [semantic versioning](http://semver.org/). -## [Unreleased] - +## [3.1.1] - [2024-06-04] + +### Fixed + +- Writing an HTTP 1xx status codes no longer results in a 200 being sent in + addition given the expectation is that a follow-up status code will be written + later. The exception is `101 Switching Protocols` since this is terminal. This + matches `net/http` behavior. + +## [3.1.0] - [2023-10-07] + +### Fixed + +- `WriteHeader` can again be used in the `ResponseWriter.Before` callback to + set HTTP status codes + +### Added + +- Satisfy `http.ResponseController` (Go 1.20+) + +## [3.0.0] - [2022-09-18] + +### Fixed + +- Replace multiple slashes at the beginning of a path with a single one to avoid + open redirects +- Avoid updating `ResponseWriter.Status()` if the status has already been + written when `ResponseWriter.WriteHeader()` is called twice + +### Changed + +- `ResponseWriter` now only implements `http` interfaces (`Flusher`, `Hijacker`, + `CloseNotifier`) if the wrapped `http.ResponseWriter` does. This is a breaking + change to make `ResponseWriter`'s interface support more accurate + +### Added + +- `ResponseWriter` now implements `io.ReaderFrom` to more efficiently send + responses via `io.Copy` ## [2.0.2] - 2020-07-17 diff --git a/vendor/github.com/urfave/negroni/v2/LICENSE b/vendor/github.com/urfave/negroni/v3/LICENSE similarity index 100% rename from vendor/github.com/urfave/negroni/v2/LICENSE rename to vendor/github.com/urfave/negroni/v3/LICENSE diff --git a/vendor/github.com/urfave/negroni/v2/README.md b/vendor/github.com/urfave/negroni/v3/README.md similarity index 64% rename from vendor/github.com/urfave/negroni/v2/README.md rename to vendor/github.com/urfave/negroni/v3/README.md index 13b2e6d0..66915193 100644 --- a/vendor/github.com/urfave/negroni/v2/README.md +++ b/vendor/github.com/urfave/negroni/v3/README.md @@ -192,6 +192,7 @@ func main() { n.Run(":8080") } ``` + If no address is provided, the `PORT` environment variable is used instead. If the `PORT` environment variable is not defined, the default address will be used. See [Run](https://godoc.org/github.com/urfave/negroni#Negroni.Run) for a complete description. @@ -492,37 +493,37 @@ will show something like - `[200 18.263µs] - Go-User-Agent/1.1 ` Here is a current list of Negroni compatible middlware. Feel free to put up a PR linking your middleware if you have built one: -| Middleware | Author | Description | -| -----------|--------|-------------| -| [authz](https://github.com/casbin/negroni-authz) | [Yang Luo](https://github.com/hsluoyz) | ACL, RBAC, ABAC Authorization middlware based on [Casbin](https://github.com/casbin/casbin) | -| [binding](https://github.com/mholt/binding) | [Matt Holt](https://github.com/mholt) | Data binding from HTTP requests into structs | -| [cloudwatch](https://github.com/cvillecsteele/negroni-cloudwatch) | [Colin Steele](https://github.com/cvillecsteele) | AWS cloudwatch metrics middleware | -| [cors](https://github.com/rs/cors) | [Olivier Poitrey](https://github.com/rs) | [Cross Origin Resource Sharing](http://www.w3.org/TR/cors/) (CORS) support | -| [csp](https://github.com/awakenetworks/csp) | [Awake Networks](https://github.com/awakenetworks) | [Content Security Policy](https://www.w3.org/TR/CSP2/) (CSP) support | -| [delay](https://github.com/jeffbmartinez/delay) | [Jeff Martinez](https://github.com/jeffbmartinez) | Add delays/latency to endpoints. Useful when testing effects of high latency | -| [New Relic Go Agent](https://github.com/yadvendar/negroni-newrelic-go-agent) | [Yadvendar Champawat](https://github.com/yadvendar) | Official [New Relic Go Agent](https://github.com/newrelic/go-agent) (currently in beta) | -| [gorelic](https://github.com/jingweno/negroni-gorelic) | [Jingwen Owen Ou](https://github.com/jingweno) | New Relic agent for Go runtime | -| [Graceful](https://github.com/tylerb/graceful) | [Tyler Bunnell](https://github.com/tylerb) | Graceful HTTP Shutdown | -| [gzip](https://github.com/phyber/negroni-gzip) | [phyber](https://github.com/phyber) | GZIP response compression | -| [JWT Middleware](https://github.com/auth0/go-jwt-middleware) | [Auth0](https://github.com/auth0) | Middleware checks for a JWT on the `Authorization` header on incoming requests and decodes it| -| [JWT Middleware](https://github.com/mfuentesg/go-jwtmiddleware) | [Marcelo Fuentes](https://github.com/mfuentesg) | JWT middleware for golang | -| [logrus](https://github.com/meatballhat/negroni-logrus) | [Dan Buch](https://github.com/meatballhat) | Logrus-based logger | -| [oauth2](https://github.com/goincremental/negroni-oauth2) | [David Bochenski](https://github.com/bochenski) | oAuth2 middleware | -| [onthefly](https://github.com/xyproto/onthefly) | [Alexander Rødseth](https://github.com/xyproto) | Generate TinySVG, HTML and CSS on the fly | -| [permissions2](https://github.com/xyproto/permissions2) | [Alexander Rødseth](https://github.com/xyproto) | Cookies, users and permissions | -| [prometheus](https://github.com/zbindenren/negroni-prometheus) | [Rene Zbinden](https://github.com/zbindenren) | Easily create metrics endpoint for the [prometheus](http://prometheus.io) instrumentation tool | -| [prometheus](https://github.com/slok/go-prometheus-middleware) | [Xabier Larrakoetxea](https://github.com/slok) | [Prometheus](http://prometheus.io) metrics with multiple options that follow standards and try to be measured in a efficent way | -| [render](https://github.com/unrolled/render) | [Cory Jacobsen](https://github.com/unrolled) | Render JSON, XML and HTML templates | -| [RestGate](https://github.com/pjebs/restgate) | [Prasanga Siripala](https://github.com/pjebs) | Secure authentication for REST API endpoints | -| [secure](https://github.com/unrolled/secure) | [Cory Jacobsen](https://github.com/unrolled) | Middleware that implements a few quick security wins | -| [sessions](https://github.com/goincremental/negroni-sessions) | [David Bochenski](https://github.com/bochenski) | Session Management | -| [stats](https://github.com/thoas/stats) | [Florent Messa](https://github.com/thoas) | Store information about your web application (response time, etc.) | -| [VanGoH](https://github.com/auroratechnologies/vangoh) | [Taylor Wrobel](https://github.com/twrobel3) | Configurable [AWS-Style](http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html) HMAC authentication middleware | -| [xrequestid](https://github.com/pilu/xrequestid) | [Andrea Franz](https://github.com/pilu) | Middleware that assigns a random X-Request-Id header to each request | -| [mgo session](https://github.com/joeljames/nigroni-mgo-session) | [Joel James](https://github.com/joeljames) | Middleware that handles creating and closing mgo sessions per request | -| [digits](https://github.com/bamarni/digits) | [Bilal Amarni](https://github.com/bamarni) | Middleware that handles [Twitter Digits](https://get.digits.com/) authentication | -| [stats](https://github.com/guptachirag/stats) | [Chirag Gupta](https://github.com/guptachirag/stats) | Middleware that manages qps and latency stats for your endpoints and asynchronously flushes them to influx db | -| [Chaos](https://github.com/falzm/chaos) | [Marc Falzon](https://github.com/falzm) | Middleware for injecting chaotic behavior into application in a programmatic way | +| Middleware | Author | Description | +| ---------------------------------------------------------------------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | +| [authz](https://github.com/casbin/negroni-authz) | [Yang Luo](https://github.com/hsluoyz) | ACL, RBAC, ABAC Authorization middlware based on [Casbin](https://github.com/casbin/casbin) | +| [binding](https://github.com/mholt/binding) | [Matt Holt](https://github.com/mholt) | Data binding from HTTP requests into structs | +| [cloudwatch](https://github.com/cvillecsteele/negroni-cloudwatch) | [Colin Steele](https://github.com/cvillecsteele) | AWS cloudwatch metrics middleware | +| [cors](https://github.com/rs/cors) | [Olivier Poitrey](https://github.com/rs) | [Cross Origin Resource Sharing](http://www.w3.org/TR/cors/) (CORS) support | +| [csp](https://github.com/awakenetworks/csp) | [Awake Networks](https://github.com/awakenetworks) | [Content Security Policy](https://www.w3.org/TR/CSP2/) (CSP) support | +| [delay](https://github.com/jeffbmartinez/delay) | [Jeff Martinez](https://github.com/jeffbmartinez) | Add delays/latency to endpoints. Useful when testing effects of high latency | +| [New Relic Go Agent](https://github.com/yadvendar/negroni-newrelic-go-agent) | [Yadvendar Champawat](https://github.com/yadvendar) | Official [New Relic Go Agent](https://github.com/newrelic/go-agent) (currently in beta) | +| [gorelic](https://github.com/jingweno/negroni-gorelic) | [Jingwen Owen Ou](https://github.com/jingweno) | New Relic agent for Go runtime | +| [Graceful](https://github.com/tylerb/graceful) | [Tyler Bunnell](https://github.com/tylerb) | Graceful HTTP Shutdown | +| [gzip](https://github.com/phyber/negroni-gzip) | [phyber](https://github.com/phyber) | GZIP response compression | +| [JWT Middleware](https://github.com/auth0/go-jwt-middleware) | [Auth0](https://github.com/auth0) | Middleware checks for a JWT on the `Authorization` header on incoming requests and decodes it | +| [JWT Middleware](https://github.com/mfuentesg/go-jwtmiddleware) | [Marcelo Fuentes](https://github.com/mfuentesg) | JWT middleware for golang | +| [logrus](https://github.com/meatballhat/negroni-logrus) | [Dan Buch](https://github.com/meatballhat) | Logrus-based logger | +| [oauth2](https://github.com/goincremental/negroni-oauth2) | [David Bochenski](https://github.com/bochenski) | oAuth2 middleware | +| [onthefly](https://github.com/xyproto/onthefly) | [Alexander Rødseth](https://github.com/xyproto) | Generate TinySVG, HTML and CSS on the fly | +| [permissions2](https://github.com/xyproto/permissions2) | [Alexander Rødseth](https://github.com/xyproto) | Cookies, users and permissions | +| [prometheus](https://github.com/zbindenren/negroni-prometheus) | [Rene Zbinden](https://github.com/zbindenren) | Easily create metrics endpoint for the [prometheus](http://prometheus.io) instrumentation tool | +| [prometheus](https://github.com/slok/go-prometheus-middleware) | [Xabier Larrakoetxea](https://github.com/slok) | [Prometheus](http://prometheus.io) metrics with multiple options that follow standards and try to be measured in a efficient way | +| [render](https://github.com/unrolled/render) | [Cory Jacobsen](https://github.com/unrolled) | Render JSON, XML and HTML templates | +| [RestGate](https://github.com/pjebs/restgate) | [Prasanga Siripala](https://github.com/pjebs) | Secure authentication for REST API endpoints | +| [secure](https://github.com/unrolled/secure) | [Cory Jacobsen](https://github.com/unrolled) | Middleware that implements a few quick security wins | +| [sessions](https://github.com/goincremental/negroni-sessions) | [David Bochenski](https://github.com/bochenski) | Session Management | +| [stats](https://github.com/thoas/stats) | [Florent Messa](https://github.com/thoas) | Store information about your web application (response time, etc.) | +| [VanGoH](https://github.com/auroratechnologies/vangoh) | [Taylor Wrobel](https://github.com/twrobel3) | Configurable [AWS-Style](http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html) HMAC authentication middleware | +| [xrequestid](https://github.com/pilu/xrequestid) | [Andrea Franz](https://github.com/pilu) | Middleware that assigns a random X-Request-Id header to each request | +| [mgo session](https://github.com/joeljames/nigroni-mgo-session) | [Joel James](https://github.com/joeljames) | Middleware that handles creating and closing mgo sessions per request | +| [digits](https://github.com/bamarni/digits) | [Bilal Amarni](https://github.com/bamarni) | Middleware that handles [Twitter Digits](https://get.digits.com/) authentication | +| [stats](https://github.com/guptachirag/stats) | [Chirag Gupta](https://github.com/guptachirag/stats) | Middleware that manages qps and latency stats for your endpoints and asynchronously flushes them to influx db | +| [Chaos](https://github.com/falzm/chaos) | [Marc Falzon](https://github.com/falzm) | Middleware for injecting chaotic behavior into application in a programmatic way | ## Examples diff --git a/vendor/github.com/urfave/negroni/v2/doc.go b/vendor/github.com/urfave/negroni/v3/doc.go similarity index 100% rename from vendor/github.com/urfave/negroni/v2/doc.go rename to vendor/github.com/urfave/negroni/v3/doc.go diff --git a/vendor/github.com/urfave/negroni/v2/logger.go b/vendor/github.com/urfave/negroni/v3/logger.go similarity index 100% rename from vendor/github.com/urfave/negroni/v2/logger.go rename to vendor/github.com/urfave/negroni/v3/logger.go diff --git a/vendor/github.com/urfave/negroni/v2/negroni.go b/vendor/github.com/urfave/negroni/v3/negroni.go similarity index 99% rename from vendor/github.com/urfave/negroni/v2/negroni.go rename to vendor/github.com/urfave/negroni/v3/negroni.go index c0fa2d43..7471bbb8 100644 --- a/vendor/github.com/urfave/negroni/v2/negroni.go +++ b/vendor/github.com/urfave/negroni/v3/negroni.go @@ -11,6 +11,10 @@ const ( DefaultAddress = ":8080" ) +func init() { + initFeaturePicker() +} + // Handler handler is an interface that objects can implement to be registered to serve as middleware // in the Negroni middleware stack. // ServeHTTP should yield to the next middleware in the chain by invoking the next http.HandlerFunc diff --git a/vendor/github.com/urfave/negroni/v2/recovery.go b/vendor/github.com/urfave/negroni/v3/recovery.go similarity index 100% rename from vendor/github.com/urfave/negroni/v2/recovery.go rename to vendor/github.com/urfave/negroni/v3/recovery.go diff --git a/vendor/github.com/urfave/negroni/v2/response_writer.go b/vendor/github.com/urfave/negroni/v3/response_writer.go similarity index 54% rename from vendor/github.com/urfave/negroni/v2/response_writer.go rename to vendor/github.com/urfave/negroni/v3/response_writer.go index 2066d5fc..524956e1 100644 --- a/vendor/github.com/urfave/negroni/v2/response_writer.go +++ b/vendor/github.com/urfave/negroni/v3/response_writer.go @@ -1,9 +1,7 @@ package negroni import ( - "bufio" - "errors" - "net" + "io" "net/http" ) @@ -12,7 +10,7 @@ import ( // if the functionality calls for it. type ResponseWriter interface { http.ResponseWriter - http.Flusher + // Status returns the status code of the response or 0 if the response has // not been written Status() int @@ -27,29 +25,39 @@ type ResponseWriter interface { type beforeFunc func(ResponseWriter) -// NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter +// NewResponseWriter creates a ResponseWriter that wraps a http.ResponseWriter func NewResponseWriter(rw http.ResponseWriter) ResponseWriter { nrw := &responseWriter{ ResponseWriter: rw, } - if _, ok := rw.(http.CloseNotifier); ok { - return &responseWriterCloseNotifer{nrw} - } - - return nrw + return wrapFeature(nrw) } type responseWriter struct { http.ResponseWriter - status int - size int - beforeFuncs []beforeFunc + pendingStatus int + status int + size int + beforeFuncs []beforeFunc + callingBefores bool } func (rw *responseWriter) WriteHeader(s int) { - rw.status = s + if rw.Written() { + return + } + + rw.pendingStatus = s rw.callBefore() + + // Any of the rw.beforeFuncs may have written a header, + // so check again to see if any work is necessary. + if rw.Written() { + return + } + + rw.status = s rw.ResponseWriter.WriteHeader(s) } @@ -63,8 +71,30 @@ func (rw *responseWriter) Write(b []byte) (int, error) { return size, err } +// ReadFrom exposes underlying http.ResponseWriter to io.Copy and if it implements +// io.ReaderFrom, it can take advantage of optimizations such as sendfile, io.Copy +// with sync.Pool's buffer which is in http.(*response).ReadFrom and so on. +func (rw *responseWriter) ReadFrom(r io.Reader) (n int64, err error) { + if !rw.Written() { + // The status will be StatusOK if WriteHeader has not been called yet + rw.WriteHeader(http.StatusOK) + } + n, err = io.Copy(rw.ResponseWriter, r) + rw.size += int(n) + return +} + +// Satisfy http.ResponseController support (Go 1.20+) +func (rw *responseWriter) Unwrap() http.ResponseWriter { + return rw.ResponseWriter +} + func (rw *responseWriter) Status() int { - return rw.status + if rw.Written() { + return rw.status + } + + return rw.pendingStatus } func (rw *responseWriter) Size() int { @@ -72,46 +102,24 @@ func (rw *responseWriter) Size() int { } func (rw *responseWriter) Written() bool { - return rw.status != 0 + return rw.status >= http.StatusOK || rw.status == http.StatusSwitchingProtocols // treat all 1xx codes aside from SwitchingProtocols as non-terminal } func (rw *responseWriter) Before(before func(ResponseWriter)) { rw.beforeFuncs = append(rw.beforeFuncs, before) } -func (rw *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { - hijacker, ok := rw.ResponseWriter.(http.Hijacker) - if !ok { - return nil, nil, errors.New("the ResponseWriter doesn't support the Hijacker interface") +func (rw *responseWriter) callBefore() { + // Don't recursively call before() functions, to avoid infinite looping if + // one of them calls rw.WriteHeader again. + if rw.callingBefores { + return } - return hijacker.Hijack() -} -func (rw *responseWriter) callBefore() { + rw.callingBefores = true + defer func() { rw.callingBefores = false }() + for i := len(rw.beforeFuncs) - 1; i >= 0; i-- { rw.beforeFuncs[i](rw) } } - -func (rw *responseWriter) Flush() { - flusher, ok := rw.ResponseWriter.(http.Flusher) - if ok { - if !rw.Written() { - // The status will be StatusOK if WriteHeader has not been called yet - rw.WriteHeader(http.StatusOK) - } - flusher.Flush() - } -} - -// Deprecated: the CloseNotifier interface predates Go's context package. -// New code should use Request.Context instead. -// -// We still implement it for backwards compatibliity with older versions of Go -type responseWriterCloseNotifer struct { - *responseWriter -} - -func (rw *responseWriterCloseNotifer) CloseNotify() <-chan bool { - return rw.ResponseWriter.(http.CloseNotifier).CloseNotify() -} diff --git a/vendor/github.com/urfave/negroni/v3/response_writer_feature.go b/vendor/github.com/urfave/negroni/v3/response_writer_feature.go new file mode 100644 index 00000000..96c9b338 --- /dev/null +++ b/vendor/github.com/urfave/negroni/v3/response_writer_feature.go @@ -0,0 +1,107 @@ +package negroni + +import ( + "bufio" + "net" + "net/http" +) + +const ( + flusher = 1 << iota + hijacker + closeNotifier +) + +type ( + flusherFeature struct{ *responseWriter } + hijackerFeature struct{ *responseWriter } + closeNotifierFeature struct{ *responseWriter } +) + +func (f flusherFeature) Flush() { + if !f.Written() { + // The status will be StatusOK if WriteHeader has not been called yet + f.WriteHeader(http.StatusOK) + } + f.ResponseWriter.(http.Flusher).Flush() +} + +func (f hijackerFeature) Hijack() (net.Conn, *bufio.ReadWriter, error) { + return f.ResponseWriter.(http.Hijacker).Hijack() +} + +func (f closeNotifierFeature) CloseNotify() <-chan bool { + return f.ResponseWriter.(http.CloseNotifier).CloseNotify() +} + +var featurePicker = make([]func(writer *responseWriter) ResponseWriter, 8) + +func initFeaturePicker() { + featurePicker[0] = func(w *responseWriter) ResponseWriter { + return w + } + featurePicker[flusher] = func(w *responseWriter) ResponseWriter { + return struct { + *responseWriter + http.Flusher + }{w, flusherFeature{w}} + } + featurePicker[hijacker] = func(w *responseWriter) ResponseWriter { + return struct { + *responseWriter + http.Hijacker + }{w, hijackerFeature{w}} + } + featurePicker[closeNotifier] = func(w *responseWriter) ResponseWriter { + return struct { + *responseWriter + http.Flusher + }{w, flusherFeature{w}} + } + featurePicker[flusher|hijacker] = func(w *responseWriter) ResponseWriter { + return struct { + *responseWriter + http.Flusher + http.Hijacker + }{w, flusherFeature{w}, hijackerFeature{w}} + } + featurePicker[flusher|closeNotifier] = func(w *responseWriter) ResponseWriter { + return struct { + *responseWriter + http.Flusher + http.CloseNotifier + }{w, flusherFeature{w}, closeNotifierFeature{w}} + } + featurePicker[hijacker|closeNotifier] = func(w *responseWriter) ResponseWriter { + return struct { + *responseWriter + http.Hijacker + http.CloseNotifier + }{w, hijackerFeature{w}, closeNotifierFeature{w}} + } + featurePicker[flusher|hijacker|closeNotifier] = func(w *responseWriter) ResponseWriter { + return struct { + *responseWriter + http.Flusher + http.Hijacker + http.CloseNotifier + }{w, flusherFeature{w}, hijackerFeature{w}, closeNotifierFeature{w}} + } +} + +func wrapFeature(w *responseWriter) ResponseWriter { + rw := w.ResponseWriter + + feature := 0 + if _, ok := rw.(http.Flusher); ok { + feature |= flusher + } + if _, ok := rw.(http.Hijacker); ok { + feature |= hijacker + } + if _, ok := rw.(http.CloseNotifier); ok { + feature |= closeNotifier + } + + return featurePicker[feature](w) +} diff --git a/vendor/github.com/urfave/negroni/v2/response_writer_pusher.go b/vendor/github.com/urfave/negroni/v3/response_writer_pusher.go similarity index 100% rename from vendor/github.com/urfave/negroni/v2/response_writer_pusher.go rename to vendor/github.com/urfave/negroni/v3/response_writer_pusher.go diff --git a/vendor/github.com/urfave/negroni/v2/static.go b/vendor/github.com/urfave/negroni/v3/static.go similarity index 94% rename from vendor/github.com/urfave/negroni/v2/static.go rename to vendor/github.com/urfave/negroni/v3/static.go index 34be967c..3ce44f96 100644 --- a/vendor/github.com/urfave/negroni/v2/static.go +++ b/vendor/github.com/urfave/negroni/v3/static.go @@ -65,6 +65,9 @@ func (s *Static) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.Ha if fi.IsDir() { // redirect if missing trailing slash if !strings.HasSuffix(r.URL.Path, "/") { + if strings.HasPrefix(r.URL.Path, "//") { + r.URL.Path = "/" + strings.TrimLeft(r.URL.Path, "/") + } http.Redirect(rw, r, r.URL.Path+"/", http.StatusFound) return } diff --git a/vendor/modules.txt b/vendor/modules.txt index 318c20a7..011b4277 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -151,7 +151,9 @@ github.com/tklauser/numcpus github.com/urfave/negroni # github.com/urfave/negroni/v2 v2.0.2 ## explicit -github.com/urfave/negroni/v2 +# github.com/urfave/negroni/v3 v3.1.1 +## explicit; go 1.17 +github.com/urfave/negroni/v3 # golang.org/x/sys v0.27.0 ## explicit; go 1.18 golang.org/x/sys/unix