mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-03-29 16:19:58 +00:00
json-dns/response.go: Fix variant question response in Response.Question
Known affected DoH server:
https://www.alidns.com/faqs/#dns-safe
This commit is contained in:
@@ -24,9 +24,29 @@
|
||||
package jsonDNS
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type QuestionList []Question
|
||||
|
||||
// Fix variant question response in Response.Question
|
||||
//
|
||||
// Solution taken from:
|
||||
// https://engineering.bitnami.com/articles/dealing-with-json-with-non-homogeneous-types-in-go.html
|
||||
// https://archive.is/NU4zR
|
||||
func (ql *QuestionList) UnmarshalJSON(b []byte) error {
|
||||
if len(b) > 0 && b[0] == '[' {
|
||||
return json.Unmarshal(b, (*[]Question)(ql))
|
||||
}
|
||||
var q Question
|
||||
if err := json.Unmarshal(b, &q); err != nil {
|
||||
return err
|
||||
}
|
||||
*ql = []Question{q}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
// Standard DNS response code (32 bit integer)
|
||||
Status uint32 `json:"Status"`
|
||||
@@ -40,13 +60,13 @@ type Response struct {
|
||||
// FIXME: We don't have DNSSEC yet! This bit is not reliable!
|
||||
AD bool `json:"AD"`
|
||||
// Whether the client asked to disable DNSSEC
|
||||
CD bool `json:"CD"`
|
||||
Question []Question `json:"Question"`
|
||||
Answer []RR `json:"Answer,omitempty"`
|
||||
Authority []RR `json:"Authority,omitempty"`
|
||||
Additional []RR `json:"Additional,omitempty"`
|
||||
Comment string `json:"Comment,omitempty"`
|
||||
EdnsClientSubnet string `json:"edns_client_subnet,omitempty"`
|
||||
CD bool `json:"CD"`
|
||||
Question QuestionList `json:"Question"`
|
||||
Answer []RR `json:"Answer,omitempty"`
|
||||
Authority []RR `json:"Authority,omitempty"`
|
||||
Additional []RR `json:"Additional,omitempty"`
|
||||
Comment string `json:"Comment,omitempty"`
|
||||
EdnsClientSubnet string `json:"edns_client_subnet,omitempty"`
|
||||
// Least time-to-live
|
||||
HaveTTL bool `json:"-"`
|
||||
LeastTTL uint32 `json:"-"`
|
||||
|
||||
Reference in New Issue
Block a user