File tree 1 file changed +26
-6
lines changed
1 file changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package main
3
3
import (
4
4
"bytes"
5
5
"crypto/tls"
6
+ "encoding/base64"
6
7
"encoding/binary"
7
8
"encoding/json"
8
9
"fmt"
@@ -284,11 +285,6 @@ func handleConnection(clientConn net.Conn) {
284
285
285
286
if strings .TrimSpace (clientHello .ServerName ) == "" {
286
287
log .Println ("empty sni not allowed here" )
287
- return
288
- }
289
-
290
- if err := clientConn .SetReadDeadline (time.Time {}); err != nil {
291
- log .Println (err )
292
288
// HTTP response headers and body
293
289
response := "HTTP/1.1 502 OK\r \n " +
294
290
"Content-Type: text/plain; charset=utf-8\r \n " +
@@ -344,7 +340,31 @@ func handleDoHRequest(ctx *fasthttp.RequestCtx) {
344
340
return
345
341
}
346
342
347
- body := ctx .PostBody ()
343
+ var body []byte
344
+ var err error
345
+
346
+ switch string (ctx .Method ()) {
347
+ case "GET" :
348
+ dnsQueryParam := ctx .QueryArgs ().Peek ("dns" )
349
+ if dnsQueryParam == nil {
350
+ ctx .Error ("Missing 'dns' query parameter" , fasthttp .StatusBadRequest )
351
+ return
352
+ }
353
+ body , err = base64 .RawURLEncoding .DecodeString (string (dnsQueryParam ))
354
+ if err != nil {
355
+ ctx .Error ("Invalid 'dns' query parameter" , fasthttp .StatusBadRequest )
356
+ return
357
+ }
358
+ case "POST" :
359
+ body = ctx .PostBody ()
360
+ if len (body ) == 0 {
361
+ ctx .Error ("Empty request body" , fasthttp .StatusBadRequest )
362
+ return
363
+ }
364
+ default :
365
+ ctx .Error ("Only GET and POST methods are allowed" , fasthttp .StatusMethodNotAllowed )
366
+ return
367
+ }
348
368
349
369
dnsResponse , err := processDNSQuery (body )
350
370
if err != nil {
You can’t perform that action at this time.
0 commit comments