Codebase list golang-github-go-kit-kit / dafbd81
update context logic in httprp too Bas van Beek 7 years ago
2 changed file(s) with 1 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
1313
1414 // Server is a proxying request handler.
1515 type Server struct {
16 ctx context.Context
1716 proxy http.Handler
1817 before []RequestFunc
1918 errorEncoder func(w http.ResponseWriter, err error)
2423 // If the target's path is "/base" and the incoming request was for "/dir",
2524 // the target request will be for /base/dir.
2625 func NewServer(
27 ctx context.Context,
2826 baseURL *url.URL,
2927 options ...ServerOption,
3028 ) *Server {
3129 s := &Server{
32 ctx: ctx,
3330 proxy: httputil.NewSingleHostReverseProxy(baseURL),
3431 }
3532 for _, option := range options {
4946
5047 // ServeHTTP implements http.Handler.
5148 func (s Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
52 ctx := s.ctx
49 ctx := r.Context()
5350
5451 for _, f := range s.before {
5552 ctx = f(ctx, r)
1919 originURL, _ := url.Parse(originServer.URL)
2020
2121 handler := httptransport.NewServer(
22 context.Background(),
2322 originURL,
2423 )
2524 proxyServer := httptest.NewServer(handler)
5453 originURL, _ := url.Parse(originServer.URL)
5554
5655 handler := httptransport.NewServer(
57 context.Background(),
5856 originURL,
5957 httptransport.ServerBefore(func(ctx context.Context, r *http.Request) context.Context {
6058 r.Header.Add(headerKey, headerVal)
8179 originURL, _ := url.Parse(originServer.URL)
8280
8381 handler := httptransport.NewServer(
84 context.Background(),
8582 originURL,
8683 )
8784 proxyServer := httptest.NewServer(handler)
10299 originServer.Close()
103100
104101 handler := httptransport.NewServer(
105 context.Background(),
106102 originURL,
107103 )
108104 proxyServer := httptest.NewServer(handler)
137133 originURL, _ := url.Parse(originServer.URL)
138134
139135 handler := httptransport.NewServer(
140 context.Background(),
141136 originURL,
142137 httptransport.ServerBefore(func(ctx context.Context, r *http.Request) context.Context {
143138 r.Header.Add(headerKey, headerVal)