mirror of
https://github.com/weloe/token-go.git
synced 2025-10-09 01:10:30 +08:00
feat: add UrlNoQuery(), used to return url without query param
This commit is contained in:
@@ -253,6 +253,13 @@ func TestHttpRequest_Url(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHttpRequest_UrlNoQuery(t *testing.T) {
|
||||||
|
s := NewTestHttpRequest(t).UrlNoQuery()
|
||||||
|
if s != "https://baidu.com/api/" {
|
||||||
|
t.Errorf("Url() = %s ,want https://baidu.com/api/", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestHttpResponse_SetHeader(t *testing.T) {
|
func TestHttpResponse_SetHeader(t *testing.T) {
|
||||||
req, _ := http.NewRequest(http.MethodGet, "/", nil)
|
req, _ := http.NewRequest(http.MethodGet, "/", nil)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
|
@@ -39,6 +39,19 @@ func (d *HttpRequest) Url() string {
|
|||||||
return d.source.URL.String()
|
return d.source.URL.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *HttpRequest) UrlNoQuery() string {
|
||||||
|
var scheme string
|
||||||
|
if d.source.URL.Scheme != "" {
|
||||||
|
scheme = d.source.URL.Scheme
|
||||||
|
}
|
||||||
|
if d.source.TLS != nil {
|
||||||
|
scheme = "https"
|
||||||
|
} else {
|
||||||
|
scheme = "http"
|
||||||
|
}
|
||||||
|
return scheme + "://" + d.source.Host + d.source.URL.Path
|
||||||
|
}
|
||||||
|
|
||||||
func (d *HttpRequest) Method() string {
|
func (d *HttpRequest) Method() string {
|
||||||
return d.source.Method
|
return d.source.Method
|
||||||
}
|
}
|
||||||
|
@@ -10,8 +10,10 @@ type Request interface {
|
|||||||
Query(key string) string
|
Query(key string) string
|
||||||
// Path https://example.org/ex?a=1&a=2&b=&=3&&&& Path() return /ex
|
// Path https://example.org/ex?a=1&a=2&b=&=3&&&& Path() return /ex
|
||||||
Path() string
|
Path() string
|
||||||
// Url https://example.org//?a=1&a=2&b=&=3&&&& Url() return https://example.org/?a=1&a=2&b=&=3&&&&
|
// Url https://example.org/?a=1&a=2&b=&=3&&&& Url() return https://example.org/?a=1&a=2&b=&=3&&&&
|
||||||
Url() string
|
Url() string
|
||||||
|
// UrlNoQuery return Url without query param
|
||||||
|
UrlNoQuery() string
|
||||||
// Method request method
|
// Method request method
|
||||||
Method() string
|
Method() string
|
||||||
// Cookie get value from cookie
|
// Cookie get value from cookie
|
||||||
|
Reference in New Issue
Block a user