(t *testing.T)
| 903 | } |
| 904 | |
| 905 | func TestModifyResponseUseContext(t *testing.T) { |
| 906 | server := httptest.NewServer( |
| 907 | http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 908 | w.WriteHeader(http.StatusOK) |
| 909 | w.Write([]byte("OK")) |
| 910 | }), |
| 911 | ) |
| 912 | defer server.Close() |
| 913 | targetURL, _ := url.Parse(server.URL) |
| 914 | e := echo.New() |
| 915 | e.Use(ProxyWithConfig( |
| 916 | ProxyConfig{ |
| 917 | Balancer: &customBalancer{ |
| 918 | target: &ProxyTarget{ |
| 919 | Name: "tst", |
| 920 | URL: targetURL, |
| 921 | }, |
| 922 | }, |
| 923 | RetryCount: 1, |
| 924 | ModifyResponse: func(res *http.Response) error { |
| 925 | val := res.Request.Context().Value(testContextKey("FROM_BALANCER")) |
| 926 | if valStr, ok := val.(string); ok { |
| 927 | res.Header.Set("FROM_BALANCER", valStr) |
| 928 | } |
| 929 | return nil |
| 930 | }, |
| 931 | }, |
| 932 | )) |
| 933 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 934 | rec := httptest.NewRecorder() |
| 935 | e.ServeHTTP(rec, req) |
| 936 | assert.Equal(t, http.StatusOK, rec.Code) |
| 937 | assert.Equal(t, "OK", rec.Body.String()) |
| 938 | assert.Equal(t, "CUSTOM_BALANCER", rec.Header().Get("FROM_BALANCER")) |
| 939 | } |
| 940 | |
| 941 | func createSimpleWebSocketServer(serveTLS bool) *httptest.Server { |
| 942 | handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…