mirror of
https://github.com/openziti/zrok.git
synced 2025-02-16 10:19:18 +01:00
skeleton double-reverse proxy... sdrp
This commit is contained in:
parent
33ff69f85f
commit
5e8130fd5a
24
http/http.go
24
http/http.go
@ -1,10 +1,12 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/openziti/sdk-golang/ziti"
|
"github.com/openziti/sdk-golang/ziti"
|
||||||
"github.com/openziti/sdk-golang/ziti/config"
|
"github.com/openziti/sdk-golang/ziti/config"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -34,7 +36,25 @@ type handler struct{}
|
|||||||
|
|
||||||
func (self *handler) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
func (self *handler) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
||||||
logrus.Infof("handling request from [%v]", req.RemoteAddr)
|
logrus.Infof("handling request from [%v]", req.RemoteAddr)
|
||||||
if _, err := res.Write([]byte(time.Now().String())); err != nil {
|
|
||||||
panic(err)
|
req.Host = "localhost:3000"
|
||||||
|
req.URL.Host = "localhost:3000"
|
||||||
|
req.URL.Scheme = "http"
|
||||||
|
req.RequestURI = ""
|
||||||
|
|
||||||
|
rRes, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
res.WriteHeader(http.StatusInternalServerError)
|
||||||
|
_, _ = fmt.Fprint(res, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
n, err := io.Copy(res, rRes.Body)
|
||||||
|
if err != nil {
|
||||||
|
res.WriteHeader(http.StatusInternalServerError)
|
||||||
|
_, _ = fmt.Fprint(res, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Infof("proxied [%d] bytes", n)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user