Skip to content

Commit

Permalink
DoH: fallback to GET if a 405 HTTP status code is returned
Browse files Browse the repository at this point in the history
Some servers block POST queries. Retry with GET if we receive a
405 HTTP status code.
  • Loading branch information
jedisct1 authored and mr-karan committed Apr 24, 2021
1 parent 9da51ad commit 8dc23ce
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/resolvers/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resolvers

import (
"bytes"
"encoding/base64"
"fmt"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 8dc23ce

Please sign in to comment.