git » dnss » commit c8299e8

httpstodns: Handle "type" query parameter not being present

author Alberto Bertogli
2017-07-30 12:35:44 UTC
committer Alberto Bertogli
2017-07-30 16:21:46 UTC
parent 733e4c506153549a417e61ebcff47e9a79eb43bd

httpstodns: Handle "type" query parameter not being present

If the "type" query parameter is not present, we should default to A.

The code currently attempts to unconditionally parse the parameter,
which fails when it's not present. This patch fixes that by only parsing
if the parameter is present.

internal/httpstodns/server.go +5 -3

diff --git a/internal/httpstodns/server.go b/internal/httpstodns/server.go
index c66d661..2864a70 100644
--- a/internal/httpstodns/server.go
+++ b/internal/httpstodns/server.go
@@ -180,9 +180,11 @@ func parseQuery(u *url.URL) (query, error) {
 		return q, fmt.Errorf("name too long")
 	}
 
-	q.rrType, err = stringToRRType(vs["type"])
-	if err != nil {
-		return q, err
+	if _, ok = vs["type"]; ok {
+		q.rrType, err = stringToRRType(vs["type"])
+		if err != nil {
+			return q, err
+		}
 	}
 
 	if cd, ok := vs["cd"]; ok {