Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38f19408c2 | ||
|
|
f28211e722 |
Binary file not shown.
Binary file not shown.
@@ -41,6 +41,10 @@ func GetAuth() (string, string, bool) {
|
||||
return user, pass, user != "" && pass != ""
|
||||
}
|
||||
|
||||
func GetTrim() string {
|
||||
return conf.Get("trim").GetString()
|
||||
}
|
||||
|
||||
func GetPort() string {
|
||||
port := conf.Get("p").GetInt()
|
||||
return ":" + fmt.Sprint(port)
|
||||
|
||||
@@ -47,6 +47,7 @@ func parseArgs() (*args.ArgSet, error) {
|
||||
as.Append(args.BOOL, "compress", "enable compression", true)
|
||||
as.Append(args.STRING, "crt", "path to crt for ssl", "")
|
||||
as.Append(args.STRING, "key", "path to key for ssl", "")
|
||||
as.Append(args.STRING, "trim", "path prefix to trim, like '/abc' to change '/abc/def' to '/def'", "")
|
||||
as.Append(args.STRING, "tcp", "address for tcp only tunnel", "")
|
||||
as.Append(args.DURATION, "timeout", "timeout for tunnel", time.Minute)
|
||||
as.Append(args.STRING, "proxy", "double-comma separated (+ if auth)from,scheme://to.tld:port,,", "")
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"local/rproxy3/config"
|
||||
"local/rproxy3/storage/packable"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -25,6 +26,7 @@ type rewrite struct {
|
||||
|
||||
func (s *Server) Proxy(w http.ResponseWriter, r *http.Request) {
|
||||
newURL, err := s.lookup(mapKey(r.Host))
|
||||
r.URL.Path = strings.TrimPrefix(r.URL.Path, config.GetTrim())
|
||||
var transport http.RoundTripper
|
||||
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
transport = &redirPurge{
|
||||
|
||||
@@ -269,7 +269,8 @@ func (s *Server) Pre(foo http.HandlerFunc) http.HandlerFunc {
|
||||
w.WriteHeader(http.StatusTooManyRequests)
|
||||
return
|
||||
}
|
||||
if did := s.doCORS(w, r); did {
|
||||
w, did := s.doCORS(w, r)
|
||||
if did {
|
||||
return
|
||||
}
|
||||
if s.auth.BOAuthZ {
|
||||
@@ -288,20 +289,29 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
s.Pre(s.Proxy)(w, r)
|
||||
}
|
||||
|
||||
func (s *Server) doCORS(w http.ResponseWriter, r *http.Request) bool {
|
||||
type corsResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
}
|
||||
|
||||
func (cb corsResponseWriter) WriteHeader(code int) {
|
||||
cb.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
cb.Header().Set("Access-Control-Allow-Headers", "X-Auth-Token, content-type, Content-Type")
|
||||
cb.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
func (s *Server) doCORS(w http.ResponseWriter, r *http.Request) (http.ResponseWriter, bool) {
|
||||
key := mapKey(r.Host)
|
||||
if !config.GetCORS(key) {
|
||||
return false
|
||||
return w, false
|
||||
}
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "X-Auth-Token, content-type, Content-Type")
|
||||
w = corsResponseWriter{ResponseWriter: w}
|
||||
if r.Method != "OPTIONS" {
|
||||
return false
|
||||
return w, false
|
||||
}
|
||||
w.Header().Set("Content-Length", "0")
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS, TRACE, PATCH, HEAD, DELETE")
|
||||
return true
|
||||
return w, true
|
||||
}
|
||||
|
||||
func getProxyAuth(r *http.Request) (string, string) {
|
||||
|
||||
Reference in New Issue
Block a user