Skip to content

Commit

Permalink
naive: log request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
navigaid committed Mar 14, 2024
1 parent bacd9ba commit 273a9df
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 51 deletions.
27 changes: 0 additions & 27 deletions apps/naive/connect.go

This file was deleted.

21 changes: 0 additions & 21 deletions apps/naive/hello.go

This file was deleted.

63 changes: 63 additions & 0 deletions apps/naive/naive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package naive

import (
"context"
"log"
"net"
"net/http"

"github.com/elazarl/goproxy"
"github.com/elazarl/goproxy/ext/auth"
"github.com/smarty/cproxy/v2"
"github.com/webteleport/utils"
"github.com/webteleport/webteleport"
)

// local listener works
//
// https_proxy=http://a:b@localhost:8080 curl https://google.com -v
//
// while the remote listener doesn't
//
// http_proxy=https://naive.remotehost:pass@remotehost:8444 curl http://google.com -v
func Run([]string) error {
ln1, err := net.Listen("tcp", ":8080")
log.Println("🛸 listening on", ":8080")
ln2, err := webteleport.Listen(context.Background(), "https://ufo.k0s.io:8444/naive?naive=1")
log.Println("🛸 listening on", webteleport.ClickableURL(ln2))
if err != nil {
return err
}

proxy := goproxy.NewProxyHttpServer()
proxy.Verbose = true
// Create a BasicAuth middleware with the provided credentials
basic := auth.BasicConnect(
"Restricted",
func(user, pass string) bool {
// ok := user != "" && pass != ""
// return true || ok
return true
},
)
c := cproxy.New()

// Use the BasicAuth middleware with the proxy server
proxy.OnRequest().HandleConnect(basic)
a := &A{proxy, c}
b := utils.GinLoggerMiddleware(a)
go http.Serve(ln1, b)
return http.Serve(ln2, b)
}

type A struct {
proxy *goproxy.ProxyHttpServer
c http.Handler
}

func (a *A) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Println(r.Header)
// a.c.ServeHTTP(w, r)
a.proxy.ServeHTTP(w, r)
println()
}
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module github.com/webteleport/ufo

go 1.22.1

// replace github.com/webteleport/webteleport => ../webteleport
// replace github.com/webteleport/wtf => ../wtf
// replace github.com/webteleport/relay => ../relay
// replace github.com/webteleport/utils => ../utils
// replace github.com/webteleport/relay => ../relay
// replace github.com/webteleport/webteleport => ../webteleport

require (
connectrpc.com/connect v1.15.0
Expand All @@ -29,7 +29,7 @@ require (
github.com/vmware-labs/wasm-workers-server v1.7.0
// github.com/webteleport/caddy-webteleport v0.0.1
github.com/webteleport/auth v0.0.8
github.com/webteleport/relay v0.2.24
github.com/webteleport/relay v0.2.26
github.com/webteleport/utils v0.2.9
github.com/webteleport/webteleport v0.4.3
github.com/webteleport/wtf v0.1.8
Expand All @@ -50,6 +50,7 @@ require (
github.com/creativeprojects/go-selfupdate v1.1.3
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5
github.com/elazarl/goproxy/ext v0.0.0-20231117061959-7cc037d33fb5
github.com/smarty/cproxy/v2 v2.1.0
golang.org/x/net v0.22.0
)

Expand Down

0 comments on commit 273a9df

Please sign in to comment.