mirror of
https://github.com/sorenisanerd/gotty.git
synced 2024-11-22 12:24:25 +00:00
Merge pull request #71 from moul/header-server
Add 'Server' HTTP header with current GoTTY version
This commit is contained in:
commit
36dfe5deac
11
app/app.go
11
app/app.go
@ -53,6 +53,8 @@ type Options struct {
|
|||||||
Preferences map[string]interface{} `hcl:"preferences"`
|
Preferences map[string]interface{} `hcl:"preferences"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Version = "0.0.10"
|
||||||
|
|
||||||
var DefaultOptions = Options{
|
var DefaultOptions = Options{
|
||||||
Address: "",
|
Address: "",
|
||||||
Port: "8080",
|
Port: "8080",
|
||||||
@ -154,6 +156,8 @@ func (app *App) Run() error {
|
|||||||
siteHandler = wrapBasicAuth(siteHandler, app.options.Credential)
|
siteHandler = wrapBasicAuth(siteHandler, app.options.Credential)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
siteHandler = wrapHeaders(siteHandler)
|
||||||
|
|
||||||
wsMux := http.NewServeMux()
|
wsMux := http.NewServeMux()
|
||||||
wsMux.Handle("/", siteHandler)
|
wsMux.Handle("/", siteHandler)
|
||||||
wsMux.Handle(path+"/ws", wsHandler)
|
wsMux.Handle(path+"/ws", wsHandler)
|
||||||
@ -277,6 +281,13 @@ func wrapLogger(handler http.Handler) http.Handler {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func wrapHeaders(handler http.Handler) http.Handler {
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Server", "GoTTY/"+Version)
|
||||||
|
handler.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func wrapBasicAuth(handler http.Handler, credential string) http.Handler {
|
func wrapBasicAuth(handler http.Handler, credential string) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
token := strings.SplitN(r.Header.Get("Authorization"), " ", 2)
|
token := strings.SplitN(r.Header.Get("Authorization"), " ", 2)
|
||||||
|
2
main.go
2
main.go
@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cmd := cli.NewApp()
|
cmd := cli.NewApp()
|
||||||
cmd.Version = "0.0.10"
|
cmd.Version = app.Version
|
||||||
cmd.Name = "gotty"
|
cmd.Name = "gotty"
|
||||||
cmd.Usage = "Share your terminal as a web application"
|
cmd.Usage = "Share your terminal as a web application"
|
||||||
cmd.HideHelp = true
|
cmd.HideHelp = true
|
||||||
|
Loading…
Reference in New Issue
Block a user