mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 19:00:54 +00:00
httplib: fix the header function for User-Agent
This commit is contained in:
parent
f7cd1479ba
commit
647a47517d
@ -355,7 +355,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) {
|
|||||||
Jar: jar,
|
Jar: jar,
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.setting.UserAgent != "" {
|
if b.setting.UserAgent != "" && b.req.Header.Get("User-Agent") == "" {
|
||||||
b.req.Header.Set("User-Agent", b.setting.UserAgent)
|
b.req.Header.Set("User-Agent", b.setting.UserAgent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,3 +203,13 @@ func TestToFile(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHeader(t *testing.T) {
|
||||||
|
req := Get("http://httpbin.org/headers")
|
||||||
|
req.Header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36")
|
||||||
|
str, err := req.String()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(str)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user