Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to hook into server #487

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Config struct {
Reverse bool
KeepAlive time.Duration
TLS TLSConfig
HTTPHook http.Handler
}

// Server respresent a chisel service
Expand All @@ -45,6 +46,7 @@ type Server struct {
sessions *settings.Users
sshConfig *ssh.ServerConfig
users *settings.UserIndex
httpHook http.Handler
}

var upgrader = websocket.Upgrader{
Expand All @@ -60,6 +62,7 @@ func NewServer(c *Config) (*Server, error) {
httpServer: cnet.NewHTTPServer(),
Logger: cio.NewLogger("server"),
sessions: settings.NewUsers(),
httpHook: c.HTTPHook,
}
server.Info = true
server.users = settings.NewUserIndex(server.Logger)
Expand Down
7 changes: 6 additions & 1 deletion server/server_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (s *Server) handleClientHandler(w http.ResponseWriter, r *http.Request) {
//websockets upgrade AND has chisel prefix
upgrade := strings.ToLower(r.Header.Get("Upgrade"))
protocol := r.Header.Get("Sec-WebSocket-Protocol")
if upgrade == "websocket" {
if upgrade == "websocket" {
if protocol == chshare.ProtocolVersion {
s.handleWebsocket(w, r)
return
Expand All @@ -42,6 +42,11 @@ func (s *Server) handleClientHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(chshare.BuildVersion))
return
}

if s.httpHook != nil {
s.httpHook.ServeHTTP(w, r)
return
}
//missing :O
w.WriteHeader(404)
w.Write([]byte("Not found"))
Expand Down