mirror of
https://github.com/m13253/dns-over-https.git
synced 2024-09-21 15:57:11 +00:00
Replace Url with URL
This commit is contained in:
parent
fec1e84d5e
commit
0f35971118
@ -58,7 +58,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
||||
questionType = strconv.FormatUint(uint64(question.Qtype), 10)
|
||||
}
|
||||
|
||||
requestURL := fmt.Sprintf("%s?ct=application/dns-json&name=%s&type=%s", upstream.Url, url.QueryEscape(questionName), url.QueryEscape(questionType))
|
||||
requestURL := fmt.Sprintf("%s?ct=application/dns-json&name=%s&type=%s", upstream.URL, url.QueryEscape(questionName), url.QueryEscape(questionType))
|
||||
|
||||
if r.CheckingDisabled {
|
||||
requestURL += "&cd=1"
|
||||
@ -118,7 +118,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter
|
||||
udpSize: udpSize,
|
||||
ednsClientAddress: ednsClientAddress,
|
||||
ednsClientNetmask: ednsClientNetmask,
|
||||
currentUpstream: upstream.Url,
|
||||
currentUpstream: upstream.URL,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
||||
r.Id = requestID
|
||||
requestBase64 := base64.RawURLEncoding.EncodeToString(requestBinary)
|
||||
|
||||
requestURL := fmt.Sprintf("%s?ct=application/dns-message&dns=%s", upstream.Url, requestBase64)
|
||||
requestURL := fmt.Sprintf("%s?ct=application/dns-message&dns=%s", upstream.URL, requestBase64)
|
||||
|
||||
var req *http.Request
|
||||
if len(requestURL) < 2048 {
|
||||
@ -115,7 +115,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
req, err = http.NewRequest(http.MethodPost, upstream.Url, bytes.NewReader(requestBinary))
|
||||
req, err = http.NewRequest(http.MethodPost, upstream.URL, bytes.NewReader(requestBinary))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
reply := jsonDNS.PrepareReply(r)
|
||||
@ -159,7 +159,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter,
|
||||
udpSize: udpSize,
|
||||
ednsClientAddress: ednsClientAddress,
|
||||
ednsClientNetmask: ednsClientNetmask,
|
||||
currentUpstream: upstream.Url,
|
||||
currentUpstream: upstream.URL,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,14 +23,14 @@ func (rs *RandomSelector) Add(url string, upstreamType UpstreamType) (err error)
|
||||
case Google:
|
||||
rs.upstreams = append(rs.upstreams, &Upstream{
|
||||
Type: Google,
|
||||
Url: url,
|
||||
URL: url,
|
||||
RequestType: "application/dns-json",
|
||||
})
|
||||
|
||||
case IETF:
|
||||
rs.upstreams = append(rs.upstreams, &Upstream{
|
||||
Type: IETF,
|
||||
Url: url,
|
||||
URL: url,
|
||||
RequestType: "application/dns-message",
|
||||
})
|
||||
|
||||
|
@ -16,7 +16,7 @@ var typeMap = map[UpstreamType]string{
|
||||
|
||||
type Upstream struct {
|
||||
Type UpstreamType
|
||||
Url string
|
||||
URL string
|
||||
RequestType string
|
||||
weight int32
|
||||
effectiveWeight int32
|
||||
@ -24,5 +24,5 @@ type Upstream struct {
|
||||
}
|
||||
|
||||
func (u Upstream) String() string {
|
||||
return fmt.Sprintf("upstream type: %s, upstream url: %s", typeMap[u.Type], u.Url)
|
||||
return fmt.Sprintf("upstream type: %s, upstream url: %s", typeMap[u.Type], u.URL)
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ func (ws *WeightRoundRobinSelector) Add(url string, upstreamType UpstreamType, w
|
||||
case Google:
|
||||
ws.upstreams = append(ws.upstreams, &Upstream{
|
||||
Type: Google,
|
||||
Url: url,
|
||||
URL: url,
|
||||
RequestType: "application/dns-json",
|
||||
weight: weight,
|
||||
effectiveWeight: weight,
|
||||
@ -33,7 +33,7 @@ func (ws *WeightRoundRobinSelector) Add(url string, upstreamType UpstreamType, w
|
||||
case IETF:
|
||||
ws.upstreams = append(ws.upstreams, &Upstream{
|
||||
Type: IETF,
|
||||
Url: url,
|
||||
URL: url,
|
||||
RequestType: "application/dns-message",
|
||||
weight: weight,
|
||||
effectiveWeight: weight,
|
||||
@ -51,27 +51,27 @@ func (ws *WeightRoundRobinSelector) StartEvaluate() {
|
||||
go func() {
|
||||
for {
|
||||
for i := range ws.upstreams {
|
||||
upstreamUrl := ws.upstreams[i].Url
|
||||
upstreamURL := ws.upstreams[i].URL
|
||||
var acceptType string
|
||||
|
||||
switch ws.upstreams[i].Type {
|
||||
case Google:
|
||||
upstreamUrl += "?name=www.example.com&type=A"
|
||||
upstreamURL += "?name=www.example.com&type=A"
|
||||
acceptType = "application/dns-json"
|
||||
|
||||
case IETF:
|
||||
// www.example.com
|
||||
upstreamUrl += "?dns=q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB"
|
||||
upstreamURL += "?dns=q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB"
|
||||
acceptType = "application/dns-message"
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, upstreamUrl, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, upstreamURL, nil)
|
||||
if err != nil {
|
||||
/*log.Println("upstream:", upstreamUrl, "type:", typeMap[upstream.Type], "check failed:", err)
|
||||
/*log.Println("upstream:", upstreamURL, "type:", typeMap[upstream.Type], "check failed:", err)
|
||||
continue*/
|
||||
|
||||
// should I only log it? But if there is an error, I think when query the server will return error too
|
||||
panic("upstream: " + upstreamUrl + " type: " + typeMap[ws.upstreams[i].Type] + " check failed: " + err.Error())
|
||||
panic("upstream: " + upstreamURL + " type: " + typeMap[ws.upstreams[i].Type] + " check failed: " + err.Error())
|
||||
}
|
||||
|
||||
req.Header.Set("accept", acceptType)
|
||||
|
Loading…
Reference in New Issue
Block a user