File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -195,7 +195,7 @@ func (s *ChallSrv) dohHandler(w http.ResponseWriter, r *http.Request) {
195195 return
196196 }
197197
198- s .dnsHandlerInner (& dnsToHTTPWriter {w }, msg )
198+ s .dnsHandlerInner (& dnsToHTTPWriter {w }, msg , r . Header . Get ( "User-Agent" ) )
199199}
200200
201201// dnsHandler is a miekg/dns handler that can process a dns.Msg request and
@@ -204,18 +204,19 @@ func (s *ChallSrv) dohHandler(w http.ResponseWriter, r *http.Request) {
204204// DNS data. A host that is aliased by a CNAME record will follow that alias
205205// one level and return the requested record types for that alias' target
206206func (s * ChallSrv ) dnsHandler (w dns.ResponseWriter , r * dns.Msg ) {
207- s .dnsHandlerInner (w , r )
207+ s .dnsHandlerInner (w , r , "" )
208208}
209209
210- func (s * ChallSrv ) dnsHandlerInner (w writeMsg , r * dns.Msg ) {
210+ func (s * ChallSrv ) dnsHandlerInner (w writeMsg , r * dns.Msg , userAgent string ) {
211211 m := new (dns.Msg )
212212 m .SetReply (r )
213213 m .Compress = false
214214
215215 // For each question, add answers based on the type of question
216216 for _ , q := range r .Question {
217217 s .AddRequestEvent (DNSRequestEvent {
218- Question : q ,
218+ Question : q ,
219+ UserAgent : userAgent ,
219220 })
220221
221222 // If there is a ServFail mock set then ignore the question and set the
Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ type HTTPRequestEvent struct {
3838 // The ServerName from the ClientHello. May be empty if there was no SNI or if
3939 // the request was not HTTPS
4040 ServerName string
41+ // The User-Agent header from the request
42+ UserAgent string
4143}
4244
4345// HTTPRequestEvents always have type HTTPRequestEventType
@@ -59,6 +61,9 @@ func (e HTTPRequestEvent) Key() string {
5961type DNSRequestEvent struct {
6062 // The DNS question received.
6163 Question dns.Question
64+ // The User-Agent header from the request, may be empty
65+ // if the request was not over DoH.
66+ UserAgent string
6267}
6368
6469// DNSRequestEvents always have type DNSRequestEventType
Original file line number Diff line number Diff line change @@ -128,6 +128,7 @@ func (s *ChallSrv) ServeHTTP(w http.ResponseWriter, r *http.Request) {
128128 Host : r .Host ,
129129 HTTPS : r .TLS != nil ,
130130 ServerName : serverName ,
131+ UserAgent : r .Header .Get ("User-Agent" ),
131132 })
132133
133134 // If the request was not over HTTPS and we have a redirect, serve it.
You can’t perform that action at this time.
0 commit comments