1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-26 07:51:30 +00:00

Merge pull request #767 from JessonChan/develop

bug fixed
This commit is contained in:
astaxie 2014-08-22 22:02:40 +08:00
commit 98c2307763

View File

@ -73,64 +73,42 @@ func SetDefaultSetting(setting BeegoHttpSettings) {
} }
} }
// return *BeegoHttpRequest with specific method
func newBeegoRequest(url, method string) *BeegoHttpRequest {
req := http.Request{
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
}
var resp http.Response
req.Method = method
req.Header = http.Header{}
return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil}
}
// Get returns *BeegoHttpRequest with GET method. // Get returns *BeegoHttpRequest with GET method.
func Get(url string) *BeegoHttpRequest { func Get(url string) *BeegoHttpRequest {
var req http.Request return newBeegoRequest(url, "GET")
var resp http.Response
req.Method = "GET"
req.Header = http.Header{}
req.Proto = "HTTP/1.1"
req.ProtoMajor = 1
req.ProtoMinor = 1
return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil}
} }
// Post returns *BeegoHttpRequest with POST method. // Post returns *BeegoHttpRequest with POST method.
func Post(url string) *BeegoHttpRequest { func Post(url string) *BeegoHttpRequest {
var req http.Request return newBeegoRequest(url, "POST")
var resp http.Response
req.Method = "POST"
req.Header = http.Header{}
req.Proto = "HTTP/1.1"
req.ProtoMajor = 1
req.ProtoMinor = 1
return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil}
} }
// Put returns *BeegoHttpRequest with PUT method. // Put returns *BeegoHttpRequest with PUT method.
func Put(url string) *BeegoHttpRequest { func Put(url string) *BeegoHttpRequest {
var req http.Request return newBeegoRequest(url, "PUT")
var resp http.Response
req.Method = "PUT"
req.Header = http.Header{}
req.Proto = "HTTP/1.1"
req.ProtoMajor = 1
req.ProtoMinor = 1
return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil}
} }
// Delete returns *BeegoHttpRequest DELETE GET method. // Delete returns *BeegoHttpRequest DELETE GET method.
func Delete(url string) *BeegoHttpRequest { func Delete(url string) *BeegoHttpRequest {
var req http.Request return newBeegoRequest(url, "DELETE")
var resp http.Response
req.Method = "DELETE"
req.Header = http.Header{}
req.Proto = "HTTP/1.1"
req.ProtoMajor = 1
req.ProtoMinor = 1
return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil}
} }
// Head returns *BeegoHttpRequest with HEAD method. // Head returns *BeegoHttpRequest with HEAD method.
func Head(url string) *BeegoHttpRequest { func Head(url string) *BeegoHttpRequest {
var req http.Request return newBeegoRequest(url, "HEAD")
var resp http.Response
req.Method = "HEAD"
req.Header = http.Header{}
req.Proto = "HTTP/1.1"
req.ProtoMajor = 1
req.ProtoMinor = 1
return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil}
} }
// BeegoHttpSettings // BeegoHttpSettings
@ -341,13 +319,6 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) {
} }
b.req.URL = url b.req.URL = url
if b.setting.ShowDebug {
dump, err := httputil.DumpRequest(b.req, true)
if err != nil {
println(err.Error())
}
println(string(dump))
}
trans := b.setting.Transport trans := b.setting.Transport
@ -392,6 +363,14 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) {
b.req.Header.Set("User-Agent", b.setting.UserAgent) b.req.Header.Set("User-Agent", b.setting.UserAgent)
} }
if b.setting.ShowDebug {
dump, err := httputil.DumpRequest(b.req, true)
if err != nil {
println(err.Error())
}
println(string(dump))
}
resp, err := client.Do(b.req) resp, err := client.Do(b.req)
if err != nil { if err != nil {
return nil, err return nil, err