aboutsummaryrefslogtreecommitdiffstats
path: root/http
diff options
context:
space:
mode:
Diffstat (limited to 'http')
-rw-r--r--http/http.go24
-rw-r--r--http/http_test.go4
2 files changed, 9 insertions, 19 deletions
diff --git a/http/http.go b/http/http.go
index 98ca90d..c2c6c5c 100644
--- a/http/http.go
+++ b/http/http.go
@@ -26,7 +26,8 @@ type entry struct {
RemoteAddr net.IP `json:"remote_addr,omitempty"`
Qtype string `json:"type"`
Question string `json:"question"`
- Answers []string `json:"answers"`
+ Answers []string `json:"answers,omitempty"`
+ Rcode string `json:"rcode,omitempty"`
}
type httpError struct {
@@ -99,26 +100,15 @@ func (s *Server) cacheHandler(w http.ResponseWriter, r *http.Request) (interface
entries = append(entries, entry{
Time: v.CreatedAt.UTC().Format(time.RFC3339),
TTL: int64(v.TTL().Truncate(time.Second).Seconds()),
- Qtype: qtype(v.Qtype),
- Question: v.Question,
- Answers: v.Answers,
+ Qtype: dns.TypeToString[v.Qtype()],
+ Question: v.Question(),
+ Answers: v.Answers(),
+ Rcode: dns.RcodeToString[v.Rcode()],
})
}
return entries, nil
}
-func qtype(qtype uint16) string {
- switch qtype {
- case dns.TypeA:
- return "A"
- case dns.TypeAAAA:
- return "AAAA"
- case dns.TypeMX:
- return "MX"
- }
- return ""
-}
-
func (s *Server) logHandler(w http.ResponseWriter, r *http.Request) (interface{}, *httpError) {
logEntries, err := s.logger.Get(100)
if err != nil {
@@ -132,7 +122,7 @@ func (s *Server) logHandler(w http.ResponseWriter, r *http.Request) (interface{}
entries = append(entries, entry{
Time: le.Time.UTC().Format(time.RFC3339),
RemoteAddr: le.RemoteAddr,
- Qtype: qtype(le.Qtype),
+ Qtype: dns.TypeToString[le.Qtype],
Question: le.Question,
Answers: le.Answers,
})
diff --git a/http/http_test.go b/http/http_test.go
index fc100aa..c98577b 100644
--- a/http/http_test.go
+++ b/http/http_test.go
@@ -61,8 +61,8 @@ func TestRequests(t *testing.T) {
srv.cache.Set(1, newA("1.example.com.", 60, net.IPv4(192, 0, 2, 200)))
srv.cache.Set(2, newA("2.example.com.", 30, net.IPv4(192, 0, 2, 201)))
- var cacheResponse = "[{\"time\":\"RFC3339\",\"ttl\":30,\"type\":\"A\",\"question\":\"2.example.com.\",\"answers\":[\"192.0.2.201\"]}," +
- "{\"time\":\"RFC3339\",\"ttl\":60,\"type\":\"A\",\"question\":\"1.example.com.\",\"answers\":[\"192.0.2.200\"]}]"
+ var cacheResponse = "[{\"time\":\"RFC3339\",\"ttl\":30,\"type\":\"A\",\"question\":\"2.example.com.\",\"answers\":[\"192.0.2.201\"],\"rcode\":\"NOERROR\"}," +
+ "{\"time\":\"RFC3339\",\"ttl\":60,\"type\":\"A\",\"question\":\"1.example.com.\",\"answers\":[\"192.0.2.200\"],\"rcode\":\"NOERROR\"}]"
var logResponse = "[{\"time\":\"RFC3339\",\"remote_addr\":\"127.0.0.254\",\"type\":\"AAAA\",\"question\":\"example.com.\",\"answers\":[\"2001:db8::1\"]}," +
"{\"time\":\"RFC3339\",\"remote_addr\":\"127.0.0.42\",\"type\":\"A\",\"question\":\"example.com.\",\"answers\":[\"192.0.2.101\",\"192.0.2.100\"]}]"