mirror of
https://github.com/dstotijn/hetty
synced 2024-11-26 13:40:17 +00:00
Move proxy logic into proxy
package
This commit is contained in:
parent
ef4f829572
commit
ee8e4330c1
4 changed files with 12 additions and 12 deletions
4
main.go
4
main.go
|
@ -6,6 +6,8 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/dstotijn/gurp/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -26,7 +28,7 @@ func main() {
|
||||||
log.Fatalf("[FATAL] Could not parse CA: %v", err)
|
log.Fatalf("[FATAL] Could not parse CA: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy, err := NewProxy(caCert, tlsCA.PrivateKey)
|
proxy, err := proxy.NewProxy(caCert, tlsCA.PrivateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("[FATAL] Could not create Proxy: %v", err)
|
log.Fatalf("[FATAL] Could not create Proxy: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -13,11 +13,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var httpHandler = &httputil.ReverseProxy{
|
var httpHandler = &httputil.ReverseProxy{
|
||||||
Director: func(r *http.Request) {
|
Director: func(r *http.Request) {},
|
||||||
r.URL.Host = r.Host
|
ErrorHandler: errorHandler,
|
||||||
r.URL.Scheme = "http"
|
|
||||||
},
|
|
||||||
ErrorHandler: proxyErrorHandler,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var httpsHandler = &httputil.ReverseProxy{
|
var httpsHandler = &httputil.ReverseProxy{
|
||||||
|
@ -25,10 +22,10 @@ var httpsHandler = &httputil.ReverseProxy{
|
||||||
r.URL.Host = r.Host
|
r.URL.Host = r.Host
|
||||||
r.URL.Scheme = "https"
|
r.URL.Scheme = "https"
|
||||||
},
|
},
|
||||||
ErrorHandler: proxyErrorHandler,
|
ErrorHandler: errorHandler,
|
||||||
}
|
}
|
||||||
|
|
||||||
func proxyErrorHandler(w http.ResponseWriter, r *http.Request, err error) {
|
func errorHandler(w http.ResponseWriter, r *http.Request, err error) {
|
||||||
if err == context.Canceled {
|
if err == context.Canceled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -36,7 +33,8 @@ func proxyErrorHandler(w http.ResponseWriter, r *http.Request, err error) {
|
||||||
w.WriteHeader(http.StatusBadGateway)
|
w.WriteHeader(http.StatusBadGateway)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proxy is used to forward HTTP requests.
|
// Proxy implements http.Handler and offers MITM behaviour for modifying
|
||||||
|
// HTTP requests and responses.
|
||||||
type Proxy struct {
|
type Proxy struct {
|
||||||
certConfig *CertConfig
|
certConfig *CertConfig
|
||||||
}
|
}
|
Loading…
Reference in a new issue