(t *testing.T)
| 25 | ) |
| 26 | |
| 27 | func TestRewrite(t *testing.T) { |
| 28 | repl := caddy.NewReplacer() |
| 29 | |
| 30 | for i, tc := range []struct { |
| 31 | input, expect *http.Request |
| 32 | rule Rewrite |
| 33 | }{ |
| 34 | { |
| 35 | input: newRequest(t, "GET", "/"), |
| 36 | expect: newRequest(t, "GET", "/"), |
| 37 | }, |
| 38 | { |
| 39 | rule: Rewrite{Method: "GET", URI: "/"}, |
| 40 | input: newRequest(t, "GET", "/"), |
| 41 | expect: newRequest(t, "GET", "/"), |
| 42 | }, |
| 43 | { |
| 44 | rule: Rewrite{Method: "POST"}, |
| 45 | input: newRequest(t, "GET", "/"), |
| 46 | expect: newRequest(t, "POST", "/"), |
| 47 | }, |
| 48 | |
| 49 | { |
| 50 | rule: Rewrite{URI: "/foo"}, |
| 51 | input: newRequest(t, "GET", "/"), |
| 52 | expect: newRequest(t, "GET", "/foo"), |
| 53 | }, |
| 54 | { |
| 55 | rule: Rewrite{URI: "/foo"}, |
| 56 | input: newRequest(t, "GET", "/bar"), |
| 57 | expect: newRequest(t, "GET", "/foo"), |
| 58 | }, |
| 59 | { |
| 60 | rule: Rewrite{URI: "foo"}, |
| 61 | input: newRequest(t, "GET", "/"), |
| 62 | expect: newRequest(t, "GET", "foo"), |
| 63 | }, |
| 64 | { |
| 65 | rule: Rewrite{URI: "{http.request.uri}"}, |
| 66 | input: newRequest(t, "GET", "/bar%3Fbaz?c=d"), |
| 67 | expect: newRequest(t, "GET", "/bar%3Fbaz?c=d"), |
| 68 | }, |
| 69 | { |
| 70 | rule: Rewrite{URI: "{http.request.uri.path}"}, |
| 71 | input: newRequest(t, "GET", "/bar%3Fbaz"), |
| 72 | expect: newRequest(t, "GET", "/bar%3Fbaz"), |
| 73 | }, |
| 74 | { |
| 75 | rule: Rewrite{URI: "/foo{http.request.uri.path}"}, |
| 76 | input: newRequest(t, "GET", "/bar"), |
| 77 | expect: newRequest(t, "GET", "/foo/bar"), |
| 78 | }, |
| 79 | { |
| 80 | rule: Rewrite{URI: "/index.php?p={http.request.uri.path}"}, |
| 81 | input: newRequest(t, "GET", "/foo/bar"), |
| 82 | expect: newRequest(t, "GET", "/index.php?p=%2Ffoo%2Fbar"), |
| 83 | }, |
| 84 | { |
nothing calls this directly
no test coverage detected