oracle: send user-agent header with our requests, fix #1923
This commit is contained in:
parent
bde4e6a91f
commit
3402a3ec30
3 changed files with 11 additions and 4 deletions
|
@ -327,8 +327,8 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get implements oracle.HTTPClient interface.
|
// Get implements oracle.HTTPClient interface.
|
||||||
func (c *httpClient) Get(url string) (*http.Response, error) {
|
func (c *httpClient) Do(req *http.Request) (*http.Response, error) {
|
||||||
resp, ok := c.responses[url]
|
resp, ok := c.responses[req.URL.String()]
|
||||||
if ok {
|
if ok {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: resp.code,
|
StatusCode: resp.code,
|
||||||
|
|
|
@ -66,7 +66,7 @@ type (
|
||||||
|
|
||||||
// HTTPClient is an interface capable of doing oracle requests.
|
// HTTPClient is an interface capable of doing oracle requests.
|
||||||
HTTPClient interface {
|
HTTPClient interface {
|
||||||
Get(string) (*http.Response, error)
|
Do(*http.Request) (*http.Response, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcaster broadcasts oracle responses.
|
// Broadcaster broadcasts oracle responses.
|
||||||
|
|
|
@ -111,7 +111,14 @@ func (o *Oracle) processRequest(priv *keys.PrivateKey, req request) error {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r, err := o.Client.Get(req.Req.URL)
|
httpReq, err := http.NewRequest("GET", req.Req.URL, nil)
|
||||||
|
if err != nil {
|
||||||
|
o.Log.Warn("failed to create http request", zap.String("url", req.Req.URL), zap.Error(err))
|
||||||
|
resp.Code = transaction.Error
|
||||||
|
break
|
||||||
|
}
|
||||||
|
httpReq.Header.Set("User-Agent", "NeoOracleService/3.0")
|
||||||
|
r, err := o.Client.Do(httpReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
o.Log.Warn("oracle request failed", zap.String("url", req.Req.URL), zap.Error(err))
|
o.Log.Warn("oracle request failed", zap.String("url", req.Req.URL), zap.Error(err))
|
||||||
resp.Code = transaction.Error
|
resp.Code = transaction.Error
|
||||||
|
|
Loading…
Reference in a new issue