mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-01-21 03:15:47 +01:00
Don't use net/http
This commit is contained in:
parent
3159bc3191
commit
525927e797
@ -6,11 +6,9 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/bits"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
@ -658,28 +656,23 @@ func fetchDoHServerInfo(proxy *Proxy, name string, stamp stamps.ServerStamp, isN
|
||||
}, nil
|
||||
}
|
||||
|
||||
func fetchTargetConfigsFromWellKnown(url string) ([]ODoHTargetConfig, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
func fetchTargetConfigsFromWellKnown(proxy *Proxy, url *url.URL) ([]ODoHTargetConfig, error) {
|
||||
bin, statusCode, _, _, err := proxy.xTransport.Get(url, "application/binary", 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if statusCode < 200 || statusCode >= 300 {
|
||||
return nil, fmt.Errorf("HTTP status code was %v", statusCode)
|
||||
}
|
||||
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return parseODoHTargetConfigs(bodyBytes)
|
||||
return parseODoHTargetConfigs(bin)
|
||||
}
|
||||
|
||||
func fetchODoHTargetInfo(proxy *Proxy, name string, stamp stamps.ServerStamp, isNew bool) (ServerInfo, error) {
|
||||
odohTargetConfigs, err := fetchTargetConfigsFromWellKnown("https://" + url.PathEscape(stamp.ProviderName) + "/.well-known/odohconfigs")
|
||||
xurl, err := url.Parse("https://" + url.PathEscape(stamp.ProviderName) + "/.well-known/odohconfigs")
|
||||
if err != nil {
|
||||
return ServerInfo{}, err
|
||||
}
|
||||
odohTargetConfigs, err := fetchTargetConfigsFromWellKnown(proxy, xurl)
|
||||
if err != nil || len(odohTargetConfigs) == 0 {
|
||||
return ServerInfo{}, fmt.Errorf("[%s] does not have an Oblivious DoH configuration", name)
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ func (xTransport *XTransport) Post(url *url.URL, accept string, contentType stri
|
||||
return xTransport.Fetch("POST", url, accept, contentType, body, timeout)
|
||||
}
|
||||
|
||||
func (xTransport *XTransport) doHQLikeuery(dataType string, useGet bool, url *url.URL, body []byte, timeout time.Duration) ([]byte, int, *tls.ConnectionState, time.Duration, error) {
|
||||
func (xTransport *XTransport) dohLikeQuery(dataType string, useGet bool, url *url.URL, body []byte, timeout time.Duration) ([]byte, int, *tls.ConnectionState, time.Duration, error) {
|
||||
if useGet {
|
||||
qs := url.Query()
|
||||
encBody := base64.RawURLEncoding.EncodeToString(body)
|
||||
@ -441,9 +441,9 @@ func (xTransport *XTransport) doHQLikeuery(dataType string, useGet bool, url *ur
|
||||
}
|
||||
|
||||
func (xTransport *XTransport) DoHQuery(useGet bool, url *url.URL, body []byte, timeout time.Duration) ([]byte, int, *tls.ConnectionState, time.Duration, error) {
|
||||
return xTransport.doHQLikeuery("application/dns-message", useGet, url, body, timeout)
|
||||
return xTransport.dohLikeQuery("application/dns-message", useGet, url, body, timeout)
|
||||
}
|
||||
|
||||
func (xTransport *XTransport) ObliviousDoHQuery(useGet bool, url *url.URL, body []byte, timeout time.Duration) ([]byte, int, *tls.ConnectionState, time.Duration, error) {
|
||||
return xTransport.doHQLikeuery("application/oblivious-dns-message", useGet, url, body, timeout)
|
||||
return xTransport.dohLikeQuery("application/oblivious-dns-message", useGet, url, body, timeout)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user