File tree Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
10
10
"net/http"
11
11
"path"
12
12
"regexp"
13
+ "strings"
13
14
)
14
15
15
16
// NewRouter returns a new router instance.
@@ -367,10 +368,11 @@ func getPath(req *http.Request) string {
367
368
// as detailed here as detailed in https://golang.org/pkg/net/url/#URL
368
369
// for < 1.5 server side workaround
369
370
// http://localhost/path/here?v=1 -> /path/here
370
- re := regexp .MustCompile (req .URL .Scheme + `://` + req .URL .Host )
371
- path := re .ReplaceAllLiteralString (req .RequestURI , "" )
372
- re = regexp .MustCompile (`\?` + req .URL .RawQuery )
373
- path = re .ReplaceAllLiteralString (path , "" )
371
+ iStart := len (req .URL .Scheme + `://` + req .URL .Host )
372
+ path := req .RequestURI [iStart :]
373
+ if i := strings .LastIndex (path , "?" ); i > - 1 {
374
+ path = path [:i ]
375
+ }
374
376
return path
375
377
}
376
378
return req .URL .Path
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ import (
10
10
"errors"
11
11
"fmt"
12
12
"net/http"
13
- "regexp"
14
13
"strings"
15
14
"testing"
16
15
)
@@ -1490,12 +1489,10 @@ func newRequest(method, url string) *http.Request {
1490
1489
}
1491
1490
// extract the escaped original host+path from url
1492
1491
// http://localhost/path/here?v=1#frag -> //localhost/path/here
1493
- re := regexp .MustCompile (req .URL .Scheme + ":" )
1494
- opaque := re .ReplaceAllLiteralString (url , "" )
1495
- re = regexp .MustCompile (`\?` + req .URL .RawQuery )
1496
- opaque = re .ReplaceAllLiteralString (opaque , "" )
1497
- re = regexp .MustCompile (`#` + req .URL .Fragment )
1498
- opaque = re .ReplaceAllLiteralString (opaque , "" )
1492
+ opaque := url [len (req .URL .Scheme )+ 1 :]
1493
+ if i := strings .LastIndex (opaque , "?" ); i > - 1 {
1494
+ opaque = opaque [:i ]
1495
+ }
1499
1496
1500
1497
// Escaped host+path workaround as detailed in https://golang.org/pkg/net/url/#URL
1501
1498
// for < 1.5 client side workaround
You can’t perform that action at this time.
0 commit comments