mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
Merge pull request #13 from syumai/use-tinyutil
use tinyutil in basic-auth-proxy example
This commit is contained in:
commit
36fa4dc54a
@ -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` .
|
||||
|
||||
|
@ -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 => ../../
|
||||
|
@ -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=
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user