Skip to content

Commit bcea936

Browse files
Capture the contents of the User-Agent Header where possible (#25)
1 parent 986f82c commit bcea936

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

dns.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff 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
206206
func (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

event.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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 {
5961
type 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

httpone.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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.

0 commit comments

Comments
 (0)