@marcel91200 / caddy Mirror · read-only / commits / 67d32e67
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

Fix up matchers tests and take care of TODO in rewrite

Matthew Holt committed May 21, 2019 at 13:10 UTC 67d32e6779b8e4f67fb0902b06210596371ead7f
3 files changed +9 -10
modules/caddyhttp/matchers_test.go
+4 -4
@@ -240,10 +240,10 @@ func TestPathREMatcher(t *testing.T) {
240 }
241
242 for key, expectVal := range tc.expectRepl {
243 - placeholder := fmt.Sprintf("{matchers.path_regexp.%s}", key)
243 + placeholder := fmt.Sprintf("{http.matchers.path_regexp.%s}", key)
244 actualVal := repl.ReplaceAll(placeholder, "<empty>")
245 if actualVal != expectVal {
246 - t.Errorf("Test %d [%v]: Expected placeholder {matchers.path_regexp.%s} to be '%s' but got '%s'",
246 + t.Errorf("Test %d [%v]: Expected placeholder {http.matchers.path_regexp.%s} to be '%s' but got '%s'",
247 i, tc.match.Pattern, key, expectVal, actualVal)
248 continue
249 }
@@ -358,10 +358,10 @@ func TestHeaderREMatcher(t *testing.T) {
358 }
359
360 for key, expectVal := range tc.expectRepl {
361 - placeholder := fmt.Sprintf("{matchers.header_regexp.%s}", key)
361 + placeholder := fmt.Sprintf("{http.matchers.header_regexp.%s}", key)
362 actualVal := repl.ReplaceAll(placeholder, "<empty>")
363 if actualVal != expectVal {
364 - t.Errorf("Test %d [%v]: Expected placeholder {matchers.header_regexp.%s} to be '%s' but got '%s'",
364 + t.Errorf("Test %d [%v]: Expected placeholder {http.matchers.header_regexp.%s} to be '%s' but got '%s'",
365 i, tc.match, key, expectVal, actualVal)
366 continue
367 }
modules/caddyhttp/replacer.go
+4 -3
@@ -48,16 +48,17 @@ func addHTTPVarsToReplacer(repl caddy2.Replacer, req *http.Request, w http.Respo
48 dir, _ := path.Split(req.URL.Path)
49 return dir
50 }()
51 + m["http.request.uri.query"] = req.URL.RawQuery
52
53 + for param, vals := range req.URL.Query() {
54 + m["http.request.uri.query."+param] = strings.Join(vals, ",")
55 + }
56 for field, vals := range req.Header {
57 m["http.request.header."+strings.ToLower(field)] = strings.Join(vals, ",")
58 }
59 for _, cookie := range req.Cookies() {
60 m["http.request.cookie."+cookie.Name] = cookie.Value
61 }
58 - for param, vals := range req.URL.Query() {
59 - m["http.request.uri.query."+param] = strings.Join(vals, ",")
60 - }
62
63 hostLabels := strings.Split(req.Host, ".")
64 for i, label := range hostLabels {
modules/caddyhttp/rewrite/rewrite.go
+1 -3
@@ -36,17 +36,15 @@ func (rewr Rewrite) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddy
36 }
37
38 if rewr.URI != "" {
39 - // TODO: clean this all up, I don't think it's right
40 -
39 oldURI := r.RequestURI
40 newURI := repl.ReplaceAll(rewr.URI, "")
41 +
42 u, err := url.Parse(newURI)
43 if err != nil {
44 return caddyhttp.Error(http.StatusInternalServerError, err)
45 }
46
47 r.RequestURI = newURI
49 -
48 r.URL.Path = u.Path
49 if u.RawQuery != "" {
50 r.URL.RawQuery = u.RawQuery