ParseURL -> ParsedURL name; add method Set Get ParsedURL
This commit is contained in:
parent
137121ee59
commit
1d2bbcd22f
4
base.go
4
base.go
|
@ -13,7 +13,7 @@ func buildBodyRequest(wf *Workflow) *http.Request {
|
|||
contentType := ""
|
||||
|
||||
if wf.Body.IOBody() == nil {
|
||||
req, err = http.NewRequest(wf.Method, wf.GetStringURL(), nil)
|
||||
req, err = http.NewRequest(wf.Method, wf.GetRawURL(), nil)
|
||||
} else {
|
||||
var bodybuf *bytes.Buffer
|
||||
switch wf.Body.IOBody().(type) {
|
||||
|
@ -24,7 +24,7 @@ func buildBodyRequest(wf *Workflow) *http.Request {
|
|||
default:
|
||||
panic(errors.New("the type is not exist, type is" + reflect.TypeOf(wf.Body.IOBody).String()))
|
||||
}
|
||||
req, err = http.NewRequest(wf.Method, wf.GetStringURL(), bodybuf)
|
||||
req, err = http.NewRequest(wf.Method, wf.GetRawURL(), bodybuf)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
12
session.go
12
session.go
|
@ -93,11 +93,14 @@ type BasicAuth struct {
|
|||
|
||||
// Session 的基本方法
|
||||
type Session struct {
|
||||
auth *BasicAuth
|
||||
|
||||
body IBody
|
||||
|
||||
client *http.Client
|
||||
transport *http.Transport
|
||||
cookiejar http.CookieJar
|
||||
body IBody
|
||||
auth *BasicAuth
|
||||
|
||||
transport *http.Transport
|
||||
|
||||
Header http.Header
|
||||
Query url.Values
|
||||
|
@ -122,7 +125,7 @@ const (
|
|||
// TypeForm PostForm类型
|
||||
TypeForm = TypeURLENCODED
|
||||
|
||||
// TypeStream application/octet-stream 类型 binary
|
||||
// TypeStream application/octet-stream 只能提交一个二进制流, 很少用
|
||||
TypeStream = "application/octet-stream"
|
||||
|
||||
// TypeFormData 类型
|
||||
|
@ -281,7 +284,6 @@ func (ses *Session) SetCookies(u *url.URL, cookies []*http.Cookie) {
|
|||
|
||||
// Cookies 返回 Cookies
|
||||
func (ses *Session) Cookies(u *url.URL) []*http.Cookie {
|
||||
|
||||
return ses.cookiejar.Cookies(u)
|
||||
}
|
||||
|
||||
|
|
21
workflow.go
21
workflow.go
|
@ -22,7 +22,7 @@ func NewWorkflow(ses *Session, u string) *Workflow {
|
|||
wf := &Workflow{}
|
||||
wf.SwitchSession(ses)
|
||||
|
||||
wf.SetURL(u)
|
||||
wf.SetRawURL(u)
|
||||
|
||||
wf.Body = NewBody()
|
||||
wf.Header = make(http.Header)
|
||||
|
@ -94,14 +94,25 @@ func (wf *Workflow) DelCookie(name interface{}) *Workflow {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetStringURL 获取url的string形式
|
||||
func (wf *Workflow) GetStringURL() string {
|
||||
// GetParsedURL 获取url的string形式
|
||||
func (wf *Workflow) GetParsedURL() *url.URL {
|
||||
return wf.ParsedURL
|
||||
}
|
||||
|
||||
// SetParsedURL 获取url的string形式
|
||||
func (wf *Workflow) SetParsedURL(u *url.URL) *Workflow {
|
||||
wf.ParsedURL = u
|
||||
return wf
|
||||
}
|
||||
|
||||
// GetRawURL 获取url的string形式
|
||||
func (wf *Workflow) GetRawURL() string {
|
||||
u := strings.Split(wf.ParsedURL.String(), "?")[0] + "?" + wf.GetCombineQuery().Encode()
|
||||
return u
|
||||
}
|
||||
|
||||
// SetURL 设置 url
|
||||
func (wf *Workflow) SetURL(srcURL string) *Workflow {
|
||||
// SetRawURL 设置 url
|
||||
func (wf *Workflow) SetRawURL(srcURL string) *Workflow {
|
||||
purl, err := url.ParseRequestURI(srcURL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
Loading…
Reference in New Issue
Block a user