98c23077 by astaxie

Merge pull request #767 from JessonChan/develop

bug fixed
2 parents 35b4022e 485c2e86
...@@ -73,64 +73,42 @@ func SetDefaultSetting(setting BeegoHttpSettings) { ...@@ -73,64 +73,42 @@ func SetDefaultSetting(setting BeegoHttpSettings) {
73 } 73 }
74 } 74 }
75 75
76 // Get returns *BeegoHttpRequest with GET method. 76 // return *BeegoHttpRequest with specific method
77 func Get(url string) *BeegoHttpRequest { 77 func newBeegoRequest(url, method string) *BeegoHttpRequest {
78 var req http.Request 78 req := http.Request{
79 Proto: "HTTP/1.1",
80 ProtoMajor: 1,
81 ProtoMinor: 1,
82 }
79 var resp http.Response 83 var resp http.Response
80 req.Method = "GET" 84 req.Method = method
81 req.Header = http.Header{} 85 req.Header = http.Header{}
82 req.Proto = "HTTP/1.1"
83 req.ProtoMajor = 1
84 req.ProtoMinor = 1
85 return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil} 86 return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil}
86 } 87 }
87 88
89 // Get returns *BeegoHttpRequest with GET method.
90 func Get(url string) *BeegoHttpRequest {
91 return newBeegoRequest(url, "GET")
92 }
93
88 // Post returns *BeegoHttpRequest with POST method. 94 // Post returns *BeegoHttpRequest with POST method.
89 func Post(url string) *BeegoHttpRequest { 95 func Post(url string) *BeegoHttpRequest {
90 var req http.Request 96 return newBeegoRequest(url, "POST")
91 var resp http.Response
92 req.Method = "POST"
93 req.Header = http.Header{}
94 req.Proto = "HTTP/1.1"
95 req.ProtoMajor = 1
96 req.ProtoMinor = 1
97 return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil}
98 } 97 }
99 98
100 // Put returns *BeegoHttpRequest with PUT method. 99 // Put returns *BeegoHttpRequest with PUT method.
101 func Put(url string) *BeegoHttpRequest { 100 func Put(url string) *BeegoHttpRequest {
102 var req http.Request 101 return newBeegoRequest(url, "PUT")
103 var resp http.Response
104 req.Method = "PUT"
105 req.Header = http.Header{}
106 req.Proto = "HTTP/1.1"
107 req.ProtoMajor = 1
108 req.ProtoMinor = 1
109 return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil}
110 } 102 }
111 103
112 // Delete returns *BeegoHttpRequest DELETE GET method. 104 // Delete returns *BeegoHttpRequest DELETE GET method.
113 func Delete(url string) *BeegoHttpRequest { 105 func Delete(url string) *BeegoHttpRequest {
114 var req http.Request 106 return newBeegoRequest(url, "DELETE")
115 var resp http.Response
116 req.Method = "DELETE"
117 req.Header = http.Header{}
118 req.Proto = "HTTP/1.1"
119 req.ProtoMajor = 1
120 req.ProtoMinor = 1
121 return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil}
122 } 107 }
123 108
124 // Head returns *BeegoHttpRequest with HEAD method. 109 // Head returns *BeegoHttpRequest with HEAD method.
125 func Head(url string) *BeegoHttpRequest { 110 func Head(url string) *BeegoHttpRequest {
126 var req http.Request 111 return newBeegoRequest(url, "HEAD")
127 var resp http.Response
128 req.Method = "HEAD"
129 req.Header = http.Header{}
130 req.Proto = "HTTP/1.1"
131 req.ProtoMajor = 1
132 req.ProtoMinor = 1
133 return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting, &resp, nil}
134 } 112 }
135 113
136 // BeegoHttpSettings 114 // BeegoHttpSettings
...@@ -341,13 +319,6 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { ...@@ -341,13 +319,6 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) {
341 } 319 }
342 320
343 b.req.URL = url 321 b.req.URL = url
344 if b.setting.ShowDebug {
345 dump, err := httputil.DumpRequest(b.req, true)
346 if err != nil {
347 println(err.Error())
348 }
349 println(string(dump))
350 }
351 322
352 trans := b.setting.Transport 323 trans := b.setting.Transport
353 324
...@@ -392,6 +363,14 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { ...@@ -392,6 +363,14 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) {
392 b.req.Header.Set("User-Agent", b.setting.UserAgent) 363 b.req.Header.Set("User-Agent", b.setting.UserAgent)
393 } 364 }
394 365
366 if b.setting.ShowDebug {
367 dump, err := httputil.DumpRequest(b.req, true)
368 if err != nil {
369 println(err.Error())
370 }
371 println(string(dump))
372 }
373
395 resp, err := client.Do(b.req) 374 resp, err := client.Do(b.req)
396 if err != nil { 375 if err != nil {
397 return nil, err 376 return nil, err
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!