aboutsummaryrefslogtreecommitdiff
path: root/src/vendor/github.com/rs/xhandler
diff options
context:
space:
mode:
Diffstat (limited to 'src/vendor/github.com/rs/xhandler')
-rw-r--r--src/vendor/github.com/rs/xhandler/.travis.yml7
-rw-r--r--src/vendor/github.com/rs/xhandler/LICENSE19
-rw-r--r--src/vendor/github.com/rs/xhandler/README.md134
-rw-r--r--src/vendor/github.com/rs/xhandler/chain.go93
-rw-r--r--src/vendor/github.com/rs/xhandler/chain_example_test.go52
-rw-r--r--src/vendor/github.com/rs/xhandler/chain_test.go112
-rw-r--r--src/vendor/github.com/rs/xhandler/middleware.go59
-rw-r--r--src/vendor/github.com/rs/xhandler/middleware_test.go88
-rw-r--r--src/vendor/github.com/rs/xhandler/xhandler.go42
-rw-r--r--src/vendor/github.com/rs/xhandler/xhandler_example_test.go67
-rw-r--r--src/vendor/github.com/rs/xhandler/xhandler_test.go61
-rw-r--r--src/vendor/github.com/rs/xhandler/xmux/README.md1
12 files changed, 0 insertions, 735 deletions
diff --git a/src/vendor/github.com/rs/xhandler/.travis.yml b/src/vendor/github.com/rs/xhandler/.travis.yml
deleted file mode 100644
index b65c7a9..0000000
--- a/src/vendor/github.com/rs/xhandler/.travis.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-language: go
-go:
-- 1.5
-- tip
-matrix:
- allow_failures:
- - go: tip
diff --git a/src/vendor/github.com/rs/xhandler/LICENSE b/src/vendor/github.com/rs/xhandler/LICENSE
deleted file mode 100644
index 47c5e9d..0000000
--- a/src/vendor/github.com/rs/xhandler/LICENSE
+++ /dev/null
@@ -1,19 +0,0 @@
-Copyright (c) 2015 Olivier Poitrey <rs@dailymotion.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is furnished
-to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
diff --git a/src/vendor/github.com/rs/xhandler/README.md b/src/vendor/github.com/rs/xhandler/README.md
deleted file mode 100644
index 91c594b..0000000
--- a/src/vendor/github.com/rs/xhandler/README.md
+++ /dev/null
@@ -1,134 +0,0 @@
-# XHandler
-
-[![godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/rs/xhandler) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/rs/xhandler/master/LICENSE) [![Build Status](https://travis-ci.org/rs/xhandler.svg?branch=master)](https://travis-ci.org/rs/xhandler) [![Coverage](http://gocover.io/_badge/github.com/rs/xhandler)](http://gocover.io/github.com/rs/xhandler)
-
-XHandler is a bridge between [net/context](https://godoc.org/golang.org/x/net/context) and `http.Handler`.
-
-It lets you enforce `net/context` in your handlers without sacrificing compatibility with existing `http.Handlers` nor imposing a specific router.
-
-Thanks to `net/context` deadline management, `xhandler` is able to enforce a per request deadline and will cancel the context when the client closes the connection unexpectedly.
-
-You may create your own `net/context` aware handler pretty much the same way as you would do with http.Handler.
-
-Read more about xhandler on [Dailymotion engineering blog](http://engineering.dailymotion.com/our-way-to-go/).
-
-## Installing
-
- go get -u github.com/rs/xhandler
-
-## Usage
-
-```go
-package main
-
-import (
- "log"
- "net/http"
- "time"
-
- "github.com/rs/cors"
- "github.com/rs/xhandler"
- "golang.org/x/net/context"
-)
-
-type myMiddleware struct {
- next xhandler.HandlerC
-}
-
-func (h myMiddleware) ServeHTTPC(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- ctx = context.WithValue(ctx, "test", "World")
- h.next.ServeHTTPC(ctx, w, r)
-}
-
-func main() {
- c := xhandler.Chain{}
-
- // Add close notifier handler so context is cancelled when the client closes
- // the connection
- c.UseC(xhandler.CloseHandler)
-
- // Add timeout handler
- c.UseC(xhandler.TimeoutHandler(2 * time.Second))
-
- // Middleware putting something in the context
- c.UseC(func(next xhandler.HandlerC) xhandler.HandlerC {
- return myMiddleware{next: next}
- })
-
- // Mix it with a non-context-aware middleware handler
- c.Use(cors.Default().Handler)
-
- // Final handler (using handlerFuncC), reading from the context
- xh := xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- value := ctx.Value("test").(string)
- w.Write([]byte("Hello " + value))
- })
-
- // Bridge context aware handlers with http.Handler using xhandler.Handle()
- http.Handle("/test", c.Handler(xh))
-
- if err := http.ListenAndServe(":8080", nil); err != nil {
- log.Fatal(err)
- }
-}
-```
-
-### Using xmux
-
-Xhandler comes with an optional context aware [muxer](https://github.com/rs/xmux) forked from [httprouter](https://github.com/julienschmidt/httprouter):
-
-```go
-package main
-
-import (
- "fmt"
- "log"
- "net/http"
- "time"
-
- "github.com/rs/xhandler"
- "github.com/rs/xmux"
- "golang.org/x/net/context"
-)
-
-func main() {
- c := xhandler.Chain{}
-
- // Append a context-aware middleware handler
- c.UseC(xhandler.CloseHandler)
-
- // Another context-aware middleware handler
- c.UseC(xhandler.TimeoutHandler(2 * time.Second))
-
- mux := xmux.New()
-
- // Use c.Handler to terminate the chain with your final handler
- mux.GET("/welcome/:name", xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, req *http.Request) {
- fmt.Fprintf(w, "Welcome %s!", xmux.Params(ctx).Get("name"))
- }))
-
- if err := http.ListenAndServe(":8080", c.Handler(mux)); err != nil {
- log.Fatal(err)
- }
-}
-```
-
-See [xmux](https://github.com/rs/xmux) for more examples.
-
-## Context Aware Middleware
-
-Here is a list of `net/context` aware middleware handlers implementing `xhandler.HandlerC` interface.
-
-Feel free to put up a PR linking your middleware if you have built one:
-
-| Middleware | Author | Description |
-| ---------- | ------ | ----------- |
-| [xmux](https://github.com/rs/xmux) | [Olivier Poitrey](https://github.com/rs) | HTTP request muxer |
-| [xlog](https://github.com/rs/xlog) | [Olivier Poitrey](https://github.com/rs) | HTTP handler logger |
-| [xstats](https://github.com/rs/xstats) | [Olivier Poitrey](https://github.com/rs) | A generic client for service instrumentation |
-| [xaccess](https://github.com/rs/xaccess) | [Olivier Poitrey](https://github.com/rs) | HTTP handler access logger with [xlog](https://github.com/rs/xlog) and [xstats](https://github.com/rs/xstats) |
-| [cors](https://github.com/rs/cors) | [Olivier Poitrey](https://github.com/rs) | [Cross Origin Resource Sharing](http://www.w3.org/TR/cors/) (CORS) support |
-
-## Licenses
-
-All source code is licensed under the [MIT License](https://raw.github.com/rs/xhandler/master/LICENSE).
diff --git a/src/vendor/github.com/rs/xhandler/chain.go b/src/vendor/github.com/rs/xhandler/chain.go
deleted file mode 100644
index 042274d..0000000
--- a/src/vendor/github.com/rs/xhandler/chain.go
+++ /dev/null
@@ -1,93 +0,0 @@
-package xhandler
-
-import (
- "net/http"
-
- "golang.org/x/net/context"
-)
-
-// Chain is an helper to chain middleware handlers together for an easier
-// management.
-type Chain []func(next HandlerC) HandlerC
-
-// UseC appends a context-aware handler to the middleware chain.
-func (c *Chain) UseC(f func(next HandlerC) HandlerC) {
- *c = append(*c, f)
-}
-
-// Use appends a standard http.Handler to the middleware chain without
-// lossing track of the context when inserted between two context aware handlers.
-//
-// Caveat: the f function will be called on each request so you are better to put
-// any initialization sequence outside of this function.
-func (c *Chain) Use(f func(next http.Handler) http.Handler) {
- xf := func(next HandlerC) HandlerC {
- return HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- n := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- next.ServeHTTPC(ctx, w, r)
- })
- f(n).ServeHTTP(w, r)
- })
- }
- *c = append(*c, xf)
-}
-
-// Handler wraps the provided final handler with all the middleware appended to
-// the chain and return a new standard http.Handler instance.
-// The context.Background() context is injected automatically.
-func (c Chain) Handler(xh HandlerC) http.Handler {
- ctx := context.Background()
- return c.HandlerCtx(ctx, xh)
-}
-
-// HandlerFC is an helper to provide a function (HandlerFuncC) to Handler().
-//
-// HandlerFC is equivalent to:
-// c.Handler(xhandler.HandlerFuncC(xhc))
-func (c Chain) HandlerFC(xhf HandlerFuncC) http.Handler {
- ctx := context.Background()
- return c.HandlerCtx(ctx, HandlerFuncC(xhf))
-}
-
-// HandlerH is an helper to provide a standard http handler (http.HandlerFunc)
-// to Handler(). Your final handler won't have access the context though.
-func (c Chain) HandlerH(h http.Handler) http.Handler {
- ctx := context.Background()
- return c.HandlerCtx(ctx, HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- h.ServeHTTP(w, r)
- }))
-}
-
-// HandlerF is an helper to provide a standard http handler function
-// (http.HandlerFunc) to Handler(). Your final handler won't have access
-// the context though.
-func (c Chain) HandlerF(hf http.HandlerFunc) http.Handler {
- ctx := context.Background()
- return c.HandlerCtx(ctx, HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- hf(w, r)
- }))
-}
-
-// HandlerCtx wraps the provided final handler with all the middleware appended to
-// the chain and return a new standard http.Handler instance.
-func (c Chain) HandlerCtx(ctx context.Context, xh HandlerC) http.Handler {
- return New(ctx, c.HandlerC(xh))
-}
-
-// HandlerC wraps the provided final handler with all the middleware appended to
-// the chain and returns a HandlerC instance.
-func (c Chain) HandlerC(xh HandlerC) HandlerC {
- for i := len(c) - 1; i >= 0; i-- {
- xh = c[i](xh)
- }
- return xh
-}
-
-// HandlerCF wraps the provided final handler func with all the middleware appended to
-// the chain and returns a HandlerC instance.
-//
-// HandlerCF is equivalent to:
-// c.HandlerC(xhandler.HandlerFuncC(xhc))
-func (c Chain) HandlerCF(xhc HandlerFuncC) HandlerC {
- return c.HandlerC(HandlerFuncC(xhc))
-}
diff --git a/src/vendor/github.com/rs/xhandler/chain_example_test.go b/src/vendor/github.com/rs/xhandler/chain_example_test.go
deleted file mode 100644
index 005b5b2..0000000
--- a/src/vendor/github.com/rs/xhandler/chain_example_test.go
+++ /dev/null
@@ -1,52 +0,0 @@
-package xhandler_test
-
-import (
- "fmt"
- "net/http"
- "strings"
- "time"
-
- "github.com/rs/cors"
- "github.com/rs/xhandler"
- "golang.org/x/net/context"
-)
-
-func ExampleChain() {
- c := xhandler.Chain{}
- // Append a context-aware middleware handler
- c.UseC(xhandler.CloseHandler)
-
- // Mix it with a non-context-aware middleware handler
- c.Use(cors.Default().Handler)
-
- // Another context-aware middleware handler
- c.UseC(xhandler.TimeoutHandler(2 * time.Second))
-
- mux := http.NewServeMux()
-
- // Use c.Handler to terminate the chain with your final handler
- mux.Handle("/", c.Handler(xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, req *http.Request) {
- fmt.Fprintf(w, "Welcome to the home page!")
- })))
-
- // You can reuse the same chain for other handlers
- mux.Handle("/api", c.Handler(xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, req *http.Request) {
- fmt.Fprintf(w, "Welcome to the API!")
- })))
-}
-
-func ExampleIf() {
- c := xhandler.Chain{}
-
- // Add timeout handler only if the path match a prefix
- c.UseC(xhandler.If(
- func(ctx context.Context, w http.ResponseWriter, r *http.Request) bool {
- return strings.HasPrefix(r.URL.Path, "/with-timeout/")
- },
- xhandler.TimeoutHandler(2*time.Second),
- ))
-
- http.Handle("/", c.Handler(xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, req *http.Request) {
- fmt.Fprintf(w, "Welcome to the home page!")
- })))
-}
diff --git a/src/vendor/github.com/rs/xhandler/chain_test.go b/src/vendor/github.com/rs/xhandler/chain_test.go
deleted file mode 100644
index 0ce9410..0000000
--- a/src/vendor/github.com/rs/xhandler/chain_test.go
+++ /dev/null
@@ -1,112 +0,0 @@
-package xhandler
-
-import (
- "net/http"
- "net/http/httptest"
- "testing"
-
- "github.com/stretchr/testify/assert"
- "golang.org/x/net/context"
-)
-
-func TestAppendHandlerC(t *testing.T) {
- init := 0
- h1 := func(next HandlerC) HandlerC {
- init++
- return HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- ctx = context.WithValue(ctx, "test", 1)
- next.ServeHTTPC(ctx, w, r)
- })
- }
- h2 := func(next HandlerC) HandlerC {
- return HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- ctx = context.WithValue(ctx, "test", 2)
- next.ServeHTTPC(ctx, w, r)
- })
- }
- c := Chain{}
- c.UseC(h1)
- c.UseC(h2)
- assert.Len(t, c, 2)
-
- h := c.Handler(HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- // Test ordering
- assert.Equal(t, 2, ctx.Value("test"), "second handler should overwrite first handler's context value")
- }))
-
- h.ServeHTTP(nil, nil)
- h.ServeHTTP(nil, nil)
- assert.Equal(t, 1, init, "handler init called once")
-}
-
-func TestAppendHandler(t *testing.T) {
- init := 0
- h1 := func(next HandlerC) HandlerC {
- return HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- ctx = context.WithValue(ctx, "test", 1)
- next.ServeHTTPC(ctx, w, r)
- })
- }
- h2 := func(next http.Handler) http.Handler {
- init++
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- // Change r and w values
- w = httptest.NewRecorder()
- r = &http.Request{}
- next.ServeHTTP(w, r)
- })
- }
- c := Chain{}
- c.UseC(h1)
- c.Use(h2)
- assert.Len(t, c, 2)
-
- h := c.Handler(HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- // Test ordering
- assert.Equal(t, 1, ctx.Value("test"),
- "the first handler value should be pass through the second (non-aware) one")
- // Test r and w overwrite
- assert.NotNil(t, w)
- assert.NotNil(t, r)
- }))
-
- h.ServeHTTP(nil, nil)
- h.ServeHTTP(nil, nil)
- // There's no safe way to not initialize non ctx aware handlers on each request :/
- //assert.Equal(t, 1, init, "handler init called once")
-}
-
-func TestChainHandlerC(t *testing.T) {
- handlerCalls := 0
- h1 := func(next HandlerC) HandlerC {
- return HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- handlerCalls++
- ctx = context.WithValue(ctx, "test", 1)
- next.ServeHTTPC(ctx, w, r)
- })
- }
- h2 := func(next HandlerC) HandlerC {
- return HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- handlerCalls++
- ctx = context.WithValue(ctx, "test", 2)
- next.ServeHTTPC(ctx, w, r)
- })
- }
-
- c := Chain{}
- c.UseC(h1)
- c.UseC(h2)
- h := c.HandlerC(HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- handlerCalls++
-
- assert.Equal(t, 2, ctx.Value("test"),
- "second handler should overwrite first handler's context value")
- assert.Equal(t, 1, ctx.Value("mainCtx"),
- "the mainCtx value should be pass through")
- }))
-
- mainCtx := context.WithValue(context.Background(), "mainCtx", 1)
- h.ServeHTTPC(mainCtx, nil, nil)
-
- assert.Equal(t, 3, handlerCalls, "all handler called once")
-}
diff --git a/src/vendor/github.com/rs/xhandler/middleware.go b/src/vendor/github.com/rs/xhandler/middleware.go
deleted file mode 100644
index 5de1364..0000000
--- a/src/vendor/github.com/rs/xhandler/middleware.go
+++ /dev/null
@@ -1,59 +0,0 @@
-package xhandler
-
-import (
- "net/http"
- "time"
-
- "golang.org/x/net/context"
-)
-
-// CloseHandler returns a Handler cancelling the context when the client
-// connection close unexpectedly.
-func CloseHandler(next HandlerC) HandlerC {
- return HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- // Cancel the context if the client closes the connection
- if wcn, ok := w.(http.CloseNotifier); ok {
- var cancel context.CancelFunc
- ctx, cancel = context.WithCancel(ctx)
- defer cancel()
-
- notify := wcn.CloseNotify()
- go func() {
- select {
- case <-notify:
- cancel()
- case <-ctx.Done():
- }
- }()
- }
-
- next.ServeHTTPC(ctx, w, r)
- })
-}
-
-// TimeoutHandler returns a Handler which adds a timeout to the context.
-//
-// Child handlers have the responsability to obey the context deadline and to return
-// an appropriate error (or not) response in case of timeout.
-func TimeoutHandler(timeout time.Duration) func(next HandlerC) HandlerC {
- return func(next HandlerC) HandlerC {
- return HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- ctx, _ = context.WithTimeout(ctx, timeout)
- next.ServeHTTPC(ctx, w, r)
- })
- }
-}
-
-// If is a special handler that will skip insert the condNext handler only if a condition
-// applies at runtime.
-func If(cond func(ctx context.Context, w http.ResponseWriter, r *http.Request) bool, condNext func(next HandlerC) HandlerC) func(next HandlerC) HandlerC {
- return func(next HandlerC) HandlerC {
- return HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- if cond(ctx, w, r) {
- condNext(next).ServeHTTPC(ctx, w, r)
- } else {
- next.ServeHTTPC(ctx, w, r)
- }
- })
- }
-}
diff --git a/src/vendor/github.com/rs/xhandler/middleware_test.go b/src/vendor/github.com/rs/xhandler/middleware_test.go
deleted file mode 100644
index 51306e3..0000000
--- a/src/vendor/github.com/rs/xhandler/middleware_test.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package xhandler
-
-import (
- "log"
- "net/http"
- "net/http/httptest"
- "testing"
- "time"
-
- "github.com/stretchr/testify/assert"
- "golang.org/x/net/context"
-)
-
-func TestTimeoutHandler(t *testing.T) {
- ctx := context.WithValue(context.Background(), contextKey, "value")
- xh := TimeoutHandler(time.Second)(&handler{})
- h := New(ctx, xh)
- w := httptest.NewRecorder()
- r, err := http.NewRequest("GET", "http://example.com/foo", nil)
- if err != nil {
- log.Fatal(err)
- }
- h.ServeHTTP(w, r)
- assert.Equal(t, "value with deadline", w.Body.String())
-}
-
-type closeNotifyWriter struct {
- *httptest.ResponseRecorder
- closed bool
-}
-
-func (w *closeNotifyWriter) CloseNotify() <-chan bool {
- notify := make(chan bool, 1)
- if w.closed {
- // return an already "closed" notifier
- notify <- true
- }
- return notify
-}
-
-func TestCloseHandlerClientClose(t *testing.T) {
- ctx := context.WithValue(context.Background(), contextKey, "value")
- xh := CloseHandler(&handler{})
- h := New(ctx, xh)
- w := &closeNotifyWriter{ResponseRecorder: httptest.NewRecorder(), closed: true}
- r, err := http.NewRequest("GET", "http://example.com/foo", nil)
- if err != nil {
- log.Fatal(err)
- }
- h.ServeHTTP(w, r)
- assert.Equal(t, "value canceled", w.Body.String())
-}
-
-func TestCloseHandlerRequestEnds(t *testing.T) {
- ctx := context.WithValue(context.Background(), contextKey, "value")
- xh := CloseHandler(&handler{})
- h := New(ctx, xh)
- w := &closeNotifyWriter{ResponseRecorder: httptest.NewRecorder(), closed: false}
- r, err := http.NewRequest("GET", "http://example.com/foo", nil)
- if err != nil {
- log.Fatal(err)
- }
- h.ServeHTTP(w, r)
- assert.Equal(t, "value", w.Body.String())
-}
-
-func TestIf(t *testing.T) {
- trueHandler := HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- assert.Equal(t, "/true", r.URL.Path)
- })
- falseHandler := HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- assert.NotEqual(t, "/true", r.URL.Path)
- })
- ctx := context.WithValue(context.Background(), contextKey, "value")
- xh := If(
- func(ctx context.Context, w http.ResponseWriter, r *http.Request) bool {
- return r.URL.Path == "/true"
- },
- func(next HandlerC) HandlerC {
- return trueHandler
- },
- )(falseHandler)
- h := New(ctx, xh)
- r, _ := http.NewRequest("GET", "http://example.com/true", nil)
- h.ServeHTTP(nil, r)
- r, _ = http.NewRequest("GET", "http://example.com/false", nil)
- h.ServeHTTP(nil, r)
-}
diff --git a/src/vendor/github.com/rs/xhandler/xhandler.go b/src/vendor/github.com/rs/xhandler/xhandler.go
deleted file mode 100644
index 0dfcddf..0000000
--- a/src/vendor/github.com/rs/xhandler/xhandler.go
+++ /dev/null
@@ -1,42 +0,0 @@
-// Package xhandler provides a bridge between http.Handler and net/context.
-//
-// xhandler enforces net/context in your handlers without sacrificing
-// compatibility with existing http.Handlers nor imposing a specific router.
-//
-// Thanks to net/context deadline management, xhandler is able to enforce
-// a per request deadline and will cancel the context in when the client close
-// the connection unexpectedly.
-//
-// You may create net/context aware middlewares pretty much the same way as
-// you would do with http.Handler.
-package xhandler // import "github.com/rs/xhandler"
-
-import (
- "net/http"
-
- "golang.org/x/net/context"
-)
-
-// HandlerC is a net/context aware http.Handler
-type HandlerC interface {
- ServeHTTPC(context.Context, http.ResponseWriter, *http.Request)
-}
-
-// HandlerFuncC type is an adapter to allow the use of ordinary functions
-// as a xhandler.Handler. If f is a function with the appropriate signature,
-// xhandler.HandlerFuncC(f) is a xhandler.Handler object that calls f.
-type HandlerFuncC func(context.Context, http.ResponseWriter, *http.Request)
-
-// ServeHTTPC calls f(ctx, w, r).
-func (f HandlerFuncC) ServeHTTPC(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- f(ctx, w, r)
-}
-
-// New creates a conventional http.Handler injecting the provided root
-// context to sub handlers. This handler is used as a bridge between conventional
-// http.Handler and context aware handlers.
-func New(ctx context.Context, h HandlerC) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- h.ServeHTTPC(ctx, w, r)
- })
-}
diff --git a/src/vendor/github.com/rs/xhandler/xhandler_example_test.go b/src/vendor/github.com/rs/xhandler/xhandler_example_test.go
deleted file mode 100644
index 9f6f8a5..0000000
--- a/src/vendor/github.com/rs/xhandler/xhandler_example_test.go
+++ /dev/null
@@ -1,67 +0,0 @@
-package xhandler_test
-
-import (
- "log"
- "net/http"
- "time"
-
- "github.com/rs/xhandler"
- "golang.org/x/net/context"
-)
-
-type key int
-
-const contextKey key = 0
-
-func newContext(ctx context.Context, value string) context.Context {
- return context.WithValue(ctx, contextKey, value)
-}
-
-func fromContext(ctx context.Context) (string, bool) {
- value, ok := ctx.Value(contextKey).(string)
- return value, ok
-}
-
-func ExampleHandle() {
- var xh xhandler.HandlerC
- xh = xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- value, _ := fromContext(ctx)
- w.Write([]byte("Hello " + value))
- })
-
- xh = (func(next xhandler.HandlerC) xhandler.HandlerC {
- return xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- ctx = newContext(ctx, "World")
- next.ServeHTTPC(ctx, w, r)
- })
- })(xh)
-
- ctx := context.Background()
- // Bridge context aware handlers with http.Handler using xhandler.Handle()
- http.Handle("/", xhandler.New(ctx, xh))
-
- if err := http.ListenAndServe(":8080", nil); err != nil {
- log.Fatal(err)
- }
-}
-
-func ExampleHandleTimeout() {
- var xh xhandler.HandlerC
- xh = xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- w.Write([]byte("Hello World"))
- if _, ok := ctx.Deadline(); ok {
- w.Write([]byte(" with deadline"))
- }
- })
-
- // This handler adds a timeout to the handler
- xh = xhandler.TimeoutHandler(5 * time.Second)(xh)
-
- ctx := context.Background()
- // Bridge context aware handlers with http.Handler using xhandler.Handle()
- http.Handle("/", xhandler.New(ctx, xh))
-
- if err := http.ListenAndServe(":8080", nil); err != nil {
- log.Fatal(err)
- }
-}
diff --git a/src/vendor/github.com/rs/xhandler/xhandler_test.go b/src/vendor/github.com/rs/xhandler/xhandler_test.go
deleted file mode 100644
index 3f5021f..0000000
--- a/src/vendor/github.com/rs/xhandler/xhandler_test.go
+++ /dev/null
@@ -1,61 +0,0 @@
-package xhandler
-
-import (
- "log"
- "net/http"
- "net/http/httptest"
- "testing"
- "time"
-
- "github.com/stretchr/testify/assert"
- "golang.org/x/net/context"
-)
-
-type handler struct{}
-
-type key int
-
-const contextKey key = 0
-
-func newContext(ctx context.Context, value string) context.Context {
- return context.WithValue(ctx, contextKey, value)
-}
-
-func fromContext(ctx context.Context) (string, bool) {
- value, ok := ctx.Value(contextKey).(string)
- return value, ok
-}
-
-func (h handler) ServeHTTPC(ctx context.Context, w http.ResponseWriter, r *http.Request) {
- // Leave other go routines a chance to run
- time.Sleep(time.Nanosecond)
- value, _ := fromContext(ctx)
- if _, ok := ctx.Deadline(); ok {
- value += " with deadline"
- }
- if ctx.Err() == context.Canceled {
- value += " canceled"
- }
- w.Write([]byte(value))
-}
-
-func TestHandle(t *testing.T) {
- ctx := context.WithValue(context.Background(), contextKey, "value")
- h := New(ctx, &handler{})
- w := httptest.NewRecorder()
- r, err := http.NewRequest("GET", "http://example.com/foo", nil)
- if err != nil {
- log.Fatal(err)
- }
- h.ServeHTTP(w, r)
- assert.Equal(t, "value", w.Body.String())
-}
-
-func TestHandlerFunc(t *testing.T) {
- ok := false
- xh := HandlerFuncC(func(context.Context, http.ResponseWriter, *http.Request) {
- ok = true
- })
- xh.ServeHTTPC(nil, nil, nil)
- assert.True(t, ok)
-}
diff --git a/src/vendor/github.com/rs/xhandler/xmux/README.md b/src/vendor/github.com/rs/xhandler/xmux/README.md
deleted file mode 100644
index 6ea3c0f..0000000
--- a/src/vendor/github.com/rs/xhandler/xmux/README.md
+++ /dev/null
@@ -1 +0,0 @@
-Xmux did move to it's [own repository](https://github.com/rs/xmux/blob/master/README.md)