Simplified the code a bit
All checks were successful
Compile dohproxy / build (push) Successful in 25s
All checks were successful
Compile dohproxy / build (push) Successful in 25s
This commit is contained in:
parent
2270f0d967
commit
ca361d923b
1 changed files with 11 additions and 17 deletions
28
dohproxy.go
28
dohproxy.go
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/tls"
|
|
||||||
"flag"
|
"flag"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
@ -15,31 +14,26 @@ import (
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProtocolType represents the type of DNS protocol
|
|
||||||
type ProtocolType int
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Enum-like constants for ProtocolType
|
// Enum-like constants for ProtocolType
|
||||||
TCP ProtocolType = iota
|
TCP int = iota
|
||||||
UDP
|
UDP
|
||||||
)
|
)
|
||||||
|
|
||||||
// DoHProxy represents the DNS-over-HTTPS proxy
|
// DoHProxy represents the DNS-over-HTTPS proxy
|
||||||
type DoHProxy struct {
|
type DoHProxy struct {
|
||||||
listenAddress string
|
listenAddress string // Address to listen for DNS queries on
|
||||||
port string
|
port string // Port to listen for DNS queries on
|
||||||
upstreamURLs []string
|
upstreamURLs []string // Upstream DoH server URLs
|
||||||
client *http.Client
|
protocols []int // List of protocols to listen on
|
||||||
protocols []ProtocolType // List of protocols to listen on
|
client *http.Client //Http client that makes the requests to the upstream servers
|
||||||
logRequests bool
|
logRequests bool // Flag that enables logging
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDoHProxy initializes a new DoHProxy instance
|
// NewDoHProxy initializes a new DoHProxy instance
|
||||||
func NewDoHProxy(listenAddress, port string, upstreamURLs []string, protocols []ProtocolType, logRequests bool) *DoHProxy {
|
func NewDoHProxy(listenAddress, port string, upstreamURLs []string, protocols []int, logRequests bool) *DoHProxy {
|
||||||
// HTTP client with support for HTTP/2
|
// HTTP client with support for HTTP/2
|
||||||
transport := &http.Transport{
|
transport := &http.Transport{}
|
||||||
TLSClientConfig: &tls.Config{},
|
|
||||||
}
|
|
||||||
|
|
||||||
http2.ConfigureTransport(transport) // Enable HTTP/2 support
|
http2.ConfigureTransport(transport) // Enable HTTP/2 support
|
||||||
|
|
||||||
|
@ -186,7 +180,7 @@ WARNING:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine which protocols to use
|
// Determine which protocols to use
|
||||||
var protocols []ProtocolType
|
var protocols []int
|
||||||
if *tcpFlag {
|
if *tcpFlag {
|
||||||
protocols = append(protocols, TCP)
|
protocols = append(protocols, TCP)
|
||||||
}
|
}
|
||||||
|
@ -195,7 +189,7 @@ WARNING:
|
||||||
}
|
}
|
||||||
if !*tcpFlag && !*udpFlag {
|
if !*tcpFlag && !*udpFlag {
|
||||||
// Default to both if no specific flag is provided
|
// Default to both if no specific flag is provided
|
||||||
protocols = []ProtocolType{TCP, UDP}
|
protocols = []int{TCP, UDP}
|
||||||
}
|
}
|
||||||
if *logFlag {
|
if *logFlag {
|
||||||
log.Println("Logging requests")
|
log.Println("Logging requests")
|
||||||
|
|
Loading…
Reference in a new issue