Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:1.18

WORKDIR /usr/src/app

EXPOSE 1234

COPY . .
RUN go build -v -o /usr/local/bin/weird-proxy-thing -buildvcs=false

CMD ["weird-proxy-thing"]
29 changes: 29 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,46 @@ import (
"io"
"net/http"
"time"
"net"
"context"
)

func main() {

runServer(1234)
}


func runServer(port int) {
// TODO: split your code up mate

transport := http.DefaultTransport.(*http.Transport).Clone()

//TODO: split up code even more mate
var (
dnsResolverIP = "1.1.1.1:53" // Google DNS resolver.
dnsResolverProto = "udp" // Protocol to use for the DNS resolver
dnsResolverTimeoutMs = 5000 // Timeout (ms) for the DNS resolver (optional)
)

dialer := &net.Dialer{
Resolver: &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: time.Duration(dnsResolverTimeoutMs) * time.Millisecond,
}
return d.DialContext(ctx, dnsResolverProto, dnsResolverIP)
},
},
}

dialContext := func(ctx context.Context, network, addr string) (net.Conn, error) {
return dialer.DialContext(ctx, network, addr)
}

transport.DialContext = dialContext

transport.MaxConnsPerHost = 20 // is this hostname or IP? Dunno, yolo
transport.IdleConnTimeout = time.Minute
transport.MaxIdleConns = 20
Expand Down