This repository was archived by the owner on Nov 5, 2024. It is now read-only.
File tree 5 files changed +50
-7
lines changed
5 files changed +50
-7
lines changed Original file line number Diff line number Diff line change 1
1
package teaconst
2
2
3
3
const (
4
- TeaVersion = "0.1.9.1 "
4
+ TeaVersion = "0.1.9.2 "
5
5
6
6
TeaProcessName = "teaweb" // 进程名
7
7
TeaProductName = "TeaWeb" // 产品名
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ package teaproxy
2
2
3
3
import (
4
4
"net/http"
5
- "path/filepath"
6
5
)
7
6
8
7
// 自定义ServeMux
@@ -12,7 +11,7 @@ type HTTPServeMux struct {
12
11
13
12
func (this * HTTPServeMux ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
14
13
// 解决因为URL中包含多个/而自动跳转的问题
15
- r .URL .Path = filepath . Clean (r .URL .Path )
14
+ r .URL .Path = CleanPath (r .URL .Path )
16
15
17
16
this .ServeMux .ServeHTTP (w , r )
18
17
}
Original file line number Diff line number Diff line change 9
9
"io"
10
10
"net/http"
11
11
"net/url"
12
- "path/filepath"
13
12
"strings"
14
13
"time"
15
14
)
@@ -61,11 +60,10 @@ func (this *Request) callBackend(writer *ResponseWriter) error {
61
60
62
61
// new uri
63
62
if this .backend .HasRequestURI () {
64
- uri := filepath .Clean (this .Format (this .backend .RequestPath ()))
65
-
63
+ uri := this .Format (this .backend .RequestPath ())
66
64
u , err := url .ParseRequestURI (uri )
67
65
if err == nil {
68
- this .raw .URL .Path = u .Path
66
+ this .raw .URL .Path = CleanPath ( u .Path )
69
67
this .raw .URL .RawQuery = u .RawQuery
70
68
71
69
args := this .Format (this .backend .RequestArgs ())
Original file line number Diff line number Diff line change
1
+ package teaproxy
2
+
3
+ // 清理Path中的多于信息
4
+ func CleanPath (path string ) string {
5
+ l := len (path )
6
+ if l == 0 {
7
+ return "/"
8
+ }
9
+ result := []byte {'/' }
10
+ isSlash := true
11
+ for i := 0 ; i < l ; i ++ {
12
+ if path [i ] == '\\' || path [i ] == '/' {
13
+ if ! isSlash {
14
+ isSlash = true
15
+ result = append (result , '/' )
16
+ }
17
+ } else {
18
+ isSlash = false
19
+ result = append (result , path [i ])
20
+ }
21
+ }
22
+ return string (result )
23
+ }
Original file line number Diff line number Diff line change
1
+ package teaproxy
2
+
3
+ import (
4
+ "github.com/iwind/TeaGo/assert"
5
+ "testing"
6
+ )
7
+
8
+ func TestCleanPath (t * testing.T ) {
9
+ a := assert .NewAssertion (t )
10
+
11
+ a .IsTrue (CleanPath ("" ) == "/" )
12
+ a .IsTrue (CleanPath ("/hello/world" ) == "/hello/world" )
13
+ a .IsTrue (CleanPath ("\\ hello\\ world" ) == "/hello/world" )
14
+ a .IsTrue (CleanPath ("/\\ hello\\ //world" ) == "/hello/world" )
15
+ a .IsTrue (CleanPath ("hello/world" ) == "/hello/world" )
16
+ a .IsTrue (CleanPath ("/hello////world" ) == "/hello/world" )
17
+ }
18
+
19
+ func BenchmarkCleanPath (b * testing.B ) {
20
+ for i := 0 ; i < b .N ; i ++ {
21
+ _ = CleanPath ("/hello///world/very/long/very//long" )
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments