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

Make path-help request forward #2677

Merged
merged 2 commits into from
May 4, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 33 additions & 0 deletions http/forwarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,36 @@ func TestHTTP_Forwarding_ClientTLS(t *testing.T) {
}
}
}

func TestHTTP_Forwarding_HelpOperation(t *testing.T) {
handler1 := http.NewServeMux()
handler2 := http.NewServeMux()
handler3 := http.NewServeMux()

coreConfig := &vault.CoreConfig{}

cores := vault.TestCluster(t, []http.Handler{handler1, handler2, handler3}, coreConfig, true)
for _, core := range cores {
defer core.CloseListeners()
}
handler1.Handle("/", Handler(cores[0].Core))
handler2.Handle("/", Handler(cores[1].Core))
handler3.Handle("/", Handler(cores[2].Core))

// make it easy to get access to the active
core := cores[0].Core
vault.TestWaitActive(t, core)

testHelp := func(client *api.Client) {
help, err := client.Help("auth/token")
if err != nil {
t.Fatal(err)
}
if help == nil {
t.Fatal("help was nil")
}
}

testHelp(cores[0].Client)
testHelp(cores[1].Client)
}
12 changes: 8 additions & 4 deletions http/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import (
)

func wrapHelpHandler(h http.Handler, core *vault.Core) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
// If the help parameter is not blank, then show the help
return http.HandlerFunc(func(writer http.ResponseWriter, req *http.Request) {
// If the help parameter is not blank, then show the help. We request
// forward because standby nodes do not have mounts and other state.
if v := req.URL.Query().Get("help"); v != "" || req.Method == "HELP" {
handleHelp(core, w, req)
handleRequestForwarding(core,
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handleHelp(core, w, r)
})).ServeHTTP(writer, req)
return
}

h.ServeHTTP(w, req)
h.ServeHTTP(writer, req)
return
})
}
Expand Down