From 8c484c7772023ecbb892e19259639a75db330d3e Mon Sep 17 00:00:00 2001 From: syumai Date: Fri, 5 Aug 2022 23:10:04 +0900 Subject: [PATCH] use tinyutil in basic-auth-proxy --- examples/basic-auth-proxy/README.md | 2 -- examples/basic-auth-proxy/go.mod | 7 +++++-- examples/basic-auth-proxy/go.sum | 4 ++-- examples/basic-auth-proxy/main.go | 9 ++------- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/examples/basic-auth-proxy/README.md b/examples/basic-auth-proxy/README.md index 8496c52..d0dcc7f 100644 --- a/examples/basic-auth-proxy/README.md +++ b/examples/basic-auth-proxy/README.md @@ -1,7 +1,5 @@ # basic-auth-proxy -**Currently, not working** - * This is an example of an HTTP proxy server with Basic-Auth . * This proxy server adds Basic-Auth to `https://syum.ai` . diff --git a/examples/basic-auth-proxy/go.mod b/examples/basic-auth-proxy/go.mod index 76a88e7..5225c27 100644 --- a/examples/basic-auth-proxy/go.mod +++ b/examples/basic-auth-proxy/go.mod @@ -2,6 +2,9 @@ module github.com/syumai/basic-auth-server go 1.18 -require github.com/syumai/workers v0.0.0 +require ( + github.com/syumai/tinyutil v0.1.0 + github.com/syumai/workers v0.0.0 +) -replace github.com/syumai/workers => ../../ \ No newline at end of file +replace github.com/syumai/workers => ../../ diff --git a/examples/basic-auth-proxy/go.sum b/examples/basic-auth-proxy/go.sum index 8c27871..6fd8680 100644 --- a/examples/basic-auth-proxy/go.sum +++ b/examples/basic-auth-proxy/go.sum @@ -1,2 +1,2 @@ -github.com/syumai/workers v0.1.0 h1:z5QfQR2X+PCKzom7RodpI5J4D5YF7NT7Qwzb9AM9dgY= -github.com/syumai/workers v0.1.0/go.mod h1:alXIDhTyeTwSzh0ZgQ3cb9HQPyyYfIejupE4Z3efr14= +github.com/syumai/tinyutil v0.1.0 h1:XJeMlJqKMwhHhTFXg7qqdF+kGxDul//kkBKtMJlXm80= +github.com/syumai/tinyutil v0.1.0/go.mod h1:/owCyUs1bh6tKxH7K1Ze3M/zZtZ+vGrj3h82fgNHDFI= diff --git a/examples/basic-auth-proxy/main.go b/examples/basic-auth-proxy/main.go index d8ae696..10a9450 100644 --- a/examples/basic-auth-proxy/main.go +++ b/examples/basic-auth-proxy/main.go @@ -5,6 +5,7 @@ import ( "log" "net/http" + "github.com/syumai/tinyutil/httputil" "github.com/syumai/workers" ) @@ -32,13 +33,7 @@ func handleRequest(w http.ResponseWriter, req *http.Request) { u := *req.URL u.Scheme = "https" u.Host = "syum.ai" - proxyReq, err := http.NewRequest("GET", u.String(), nil) - if err != nil { - handleError(w, http.StatusInternalServerError, "Internal Error") - log.Printf("failed to create proxy request: %v\n", err) - return - } - resp, err := (*Transport).RoundTrip(nil, proxyReq) + resp, err := httputil.Get(u.String()) if err != nil { handleError(w, http.StatusInternalServerError, "Internal Error") log.Printf("failed to execute proxy request: %v\n", err)