2 Commits
v0.2.1 ... v0.3

Author SHA1 Message Date
Bel LaPointe
698edf7e45 insecure skip verify 2019-09-24 12:47:06 -06:00
Bel LaPointe
48e0048216 no more logger 2019-05-02 09:35:53 -06:00
6 changed files with 9 additions and 91 deletions

View File

@@ -1,5 +1,5 @@
p: 54243
r:
r:
- echo:http://localhost:49982
- echo2:http://192.168.0.86:38090
#crt: ./testdata/rproxy3server.crt

View File

@@ -106,13 +106,3 @@ func GetRewrites(hostMatch string) map[string]string {
}
return m
}
func GetProxyMode() string {
v := packable.NewString()
conf.Get(nsConf, flagMode, v)
s := v.String()
if s == "" {
return "domain"
}
return s
}

View File

@@ -14,7 +14,6 @@ import (
const nsConf = "configuration"
const flagPort = "p"
const flagMode = "mode"
const flagRoutes = "r"
const flagConf = "c"
const flagCert = "crt"
@@ -35,7 +34,6 @@ type toBind struct {
type fileConf struct {
Port string `yaml:"p"`
Mode string `yaml:"mode"`
Routes []string `yaml:"r"`
CertPath string `yaml:"crt"`
KeyPath string `yaml:"key"`
@@ -81,9 +79,6 @@ func fromFile() error {
if err := conf.Set(nsConf, flagPort, packable.NewString(c.Port)); err != nil {
return err
}
if err := conf.Set(nsConf, flagMode, packable.NewString(c.Mode)); err != nil {
return err
}
if err := conf.Set(nsConf, flagRoutes, packable.NewString(strings.Join(c.Routes, ","))); err != nil {
return err
}
@@ -117,7 +112,6 @@ func fromFile() error {
func fromFlags() error {
binds := make([]toBind, 0)
binds = append(binds, addFlag(flagPort, "51555", "port to bind to"))
binds = append(binds, addFlag(flagMode, "domain", "[domain] or [path] to match"))
binds = append(binds, addFlag(flagConf, "", "configuration file path"))
binds = append(binds, addFlag(flagRoutes, "", "comma-separated routes to map, each as from:scheme://to.tld:port"))
binds = append(binds, addFlag(flagCert, "", "path to .crt"))

View File

@@ -2,6 +2,7 @@ package server
import (
"bytes"
"crypto/tls"
"io"
"local/rproxy3/config"
"local/rproxy3/storage/packable"
@@ -24,15 +25,16 @@ type rewrite struct {
}
func (s *Server) Proxy(w http.ResponseWriter, r *http.Request) {
newURL, err := s.lookup(mapKey(r, config.GetProxyMode()))
newURL, err := s.lookup(mapKey(r.Host))
var transport http.RoundTripper
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
transport = &redirPurge{
proxyHost: r.Host,
targetHost: newURL.Host,
baseTransport: http.DefaultTransport,
}
transport = &rewrite{
rewrites: config.GetRewrites(mapKey(r, config.GetProxyMode())),
rewrites: config.GetRewrites(mapKey(r.Host)),
baseTransport: transport,
}
if err != nil {
@@ -52,20 +54,10 @@ func (s *Server) lookup(host string) (*url.URL, error) {
return v.URL(), err
}
func mapKey(r *http.Request, proxyMode string) string {
switch proxyMode {
case "domain":
host := strings.Split(r.Host, ".")[0]
host = strings.Split(host, ":")[0]
return host
case "path":
paths := strings.Split(r.URL.Path, "/")
if len(paths) < 2 {
return ""
}
return paths[1]
}
return ""
func mapKey(host string) string {
host = strings.Split(host, ".")[0]
host = strings.Split(host, ":")[0]
return host
}
func (rp *redirPurge) RoundTrip(r *http.Request) (*http.Response, error) {

View File

@@ -3,7 +3,6 @@ package server
import (
"io/ioutil"
"net/http"
"net/url"
"strings"
"testing"
)
@@ -41,35 +40,3 @@ func TestRewrite(t *testing.T) {
t.Errorf("failed to replace: got %q, want \"b\"", b)
}
}
func TestMapKey(t *testing.T) {
r := &http.Request{
Host: "a.b.c:123",
URL: &url.URL{
Path: "/c/d/e",
},
}
if v := mapKey(r, "domain"); v != "a" {
t.Errorf("failed to get domain: got %v", v)
}
if v := mapKey(r, "path"); v != "c" {
t.Errorf("failed to get domain: got %v", v)
}
r.Host = "a:123"
if v := mapKey(r, "domain"); v != "a" {
t.Errorf("failed to get domain: got %v", v)
}
r.URL.Path = ""
if v := mapKey(r, "path"); v != "" {
t.Errorf("failed to get domain: got %v", v)
}
r.URL.Path = "/"
if v := mapKey(r, "path"); v != "" {
t.Errorf("failed to get domain: got %v", v)
}
}

25
vendor/vendor.json vendored
View File

@@ -1,25 +0,0 @@
{
"comment": "",
"ignore": "test",
"package": [
{
"checksumSHA1": "GtamqiJoL7PGHsN454AoffBFMa8=",
"path": "golang.org/x/net/context",
"revision": "65e2d4e15006aab9813ff8769e768bbf4bb667a0",
"revisionTime": "2019-02-01T23:59:58Z"
},
{
"checksumSHA1": "HoCvrd3hEhsFeBOdEw7cbcfyk50=",
"path": "golang.org/x/time/rate",
"revision": "fbb02b2291d28baffd63558aa44b4b56f178d650",
"revisionTime": "2018-04-12T16:56:04Z"
},
{
"checksumSHA1": "QqDq2x8XOU7IoOR98Cx1eiV5QY8=",
"path": "gopkg.in/yaml.v2",
"revision": "51d6538a90f86fe93ac480b35f37b2be17fef232",
"revisionTime": "2018-11-15T11:05:04Z"
}
],
"rootPath": "local/rproxy3"
}