Merge pull request #13 from syumai/use-tinyutil

use tinyutil in basic-auth-proxy example
This commit is contained in:
syumai 2022-08-05 23:10:59 +09:00 committed by GitHub
commit 36fa4dc54a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 13 deletions

View File

@ -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` .

View File

@ -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 => ../../
replace github.com/syumai/workers => ../../

View File

@ -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=

View File

@ -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)