-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Removed Go HTTP client UA - Added optional bypass of websocket origin check #107 - Added basic forward proxy for debug - Fixed UI error in network utils tab
- Loading branch information
Showing
29 changed files
with
849 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Smarty | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
NOTE: Various optional and subordinate components carry their own licensing | ||
requirements and restrictions. Use of those components is subject to the terms | ||
and conditions outlined the respective license of each component. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package cproxy | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
) | ||
|
||
func New(options ...option) http.Handler { | ||
var this configuration | ||
Options.apply(options...)(&this) | ||
return newHandler(this.Filter, this.ClientConnector, this.ServerConnector, this.Monitor) | ||
} | ||
|
||
var Options singleton | ||
|
||
type singleton struct{} | ||
type option func(*configuration) | ||
|
||
type configuration struct { | ||
DialTimeout time.Duration | ||
Filter Filter | ||
DialAddress string | ||
Dialer Dialer | ||
LogConnections bool | ||
ProxyProtocol bool | ||
Initializer initializer | ||
ClientConnector clientConnector | ||
ServerConnector serverConnector | ||
Monitor monitor | ||
Logger logger | ||
} | ||
|
||
func (singleton) DialTimeout(value time.Duration) option { | ||
return func(this *configuration) { this.DialTimeout = value } | ||
} | ||
func (singleton) Filter(value Filter) option { | ||
return func(this *configuration) { this.Filter = value } | ||
} | ||
func (singleton) ClientConnector(value clientConnector) option { | ||
return func(this *configuration) { this.ClientConnector = value } | ||
} | ||
func (singleton) DialAddress(value string) option { | ||
return func(this *configuration) { this.DialAddress = value } | ||
} | ||
func (singleton) Dialer(value Dialer) option { | ||
return func(this *configuration) { this.Dialer = value } | ||
} | ||
func (singleton) LogConnections(value bool) option { | ||
return func(this *configuration) { this.LogConnections = value } | ||
} | ||
func (singleton) ProxyProtocol(value bool) option { | ||
return func(this *configuration) { this.ProxyProtocol = value } | ||
} | ||
func (singleton) Initializer(value initializer) option { | ||
return func(this *configuration) { this.Initializer = value } | ||
} | ||
func (singleton) ServerConnector(value serverConnector) option { | ||
return func(this *configuration) { this.ServerConnector = value } | ||
} | ||
func (singleton) Monitor(value monitor) option { | ||
return func(this *configuration) { this.Monitor = value } | ||
} | ||
func (singleton) Logger(value logger) option { | ||
return func(this *configuration) { this.Logger = value } | ||
} | ||
|
||
func (singleton) apply(options ...option) option { | ||
return func(this *configuration) { | ||
for _, item := range Options.defaults(options...) { | ||
item(this) | ||
} | ||
|
||
if this.Dialer == nil { | ||
this.Dialer = newDialer(this) | ||
} | ||
|
||
this.Dialer = newRoutingDialer(this) | ||
|
||
if this.ProxyProtocol { | ||
this.Initializer = newProxyProtocolInitializer() | ||
} | ||
|
||
if this.Initializer == nil { | ||
this.Initializer = nop{} | ||
} | ||
|
||
this.Initializer = newLoggingInitializer(this) | ||
|
||
if this.ServerConnector == nil { | ||
this.ServerConnector = newServerConnector(this.Dialer, this.Initializer) | ||
} | ||
} | ||
} | ||
func (singleton) defaults(options ...option) []option { | ||
return append([]option{ | ||
Options.DialTimeout(time.Second * 10), | ||
Options.Filter(newFilter()), | ||
Options.ClientConnector(newClientConnector()), | ||
Options.Initializer(nop{}), | ||
Options.Monitor(nop{}), | ||
Options.Logger(nop{}), | ||
}, options...) | ||
} | ||
|
||
type nop struct{} | ||
|
||
func (nop) Measure(int) {} | ||
func (nop) Printf(string, ...interface{}) {} | ||
func (nop) Initialize(Socket, Socket) bool { return true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cproxy | ||
|
||
import "net/http" | ||
|
||
type defaultClientConnector struct{} | ||
|
||
func newClientConnector() *defaultClientConnector { | ||
return &defaultClientConnector{} | ||
} | ||
|
||
func (this *defaultClientConnector) Connect(response http.ResponseWriter) Socket { | ||
if hijacker, ok := response.(http.Hijacker); !ok { | ||
return nil | ||
} else if socket, _, _ := hijacker.Hijack(); socket == nil { | ||
return nil // this 'else if' exists to avoid the pointer nil != interface nil issue | ||
} else { | ||
return socket | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cproxy | ||
|
||
import ( | ||
"net" | ||
"time" | ||
) | ||
|
||
type defaultDialer struct { | ||
timeout time.Duration | ||
logger logger | ||
} | ||
|
||
func newDialer(config *configuration) *defaultDialer { | ||
return &defaultDialer{timeout: config.DialTimeout, logger: config.Logger} | ||
} | ||
|
||
func (this *defaultDialer) Dial(address string) Socket { | ||
if socket, err := net.DialTimeout("tcp", address, this.timeout); err == nil { | ||
return socket | ||
} else { | ||
this.logger.Printf("[INFO] Unable to establish connection to [%s]: %s", address, err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.