DoH: fallback to GET if a 405 HTTP status code is returned
Some servers block POST queries. Retry with GET if we receive a 405 HTTP status code.pull/19/head v0.4.0
parent
9da51ad997
commit
8dc23ce8f5
|
@ -2,6 +2,7 @@ package resolvers
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
@ -64,6 +65,17 @@ func (r *DOHResolver) Lookup(question dns.Question) (Response, error) {
|
|||
if err != nil {
|
||||
return rsp, err
|
||||
}
|
||||
if resp.StatusCode == http.StatusMethodNotAllowed {
|
||||
url, err := url.Parse(r.server)
|
||||
if err != nil {
|
||||
return rsp, err
|
||||
}
|
||||
url.RawQuery = fmt.Sprintf("dns=%v", base64.RawURLEncoding.EncodeToString(b))
|
||||
resp, err = r.client.Get(url.String())
|
||||
if err != nil {
|
||||
return rsp, err
|
||||
}
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return rsp, fmt.Errorf("error from nameserver %s", resp.Status)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue