Skip to content

Commit 5ef7738

Browse files
committed
config: fix setting postrequest config
PR apache#161 introduced `postrequest` config but there was no way to update that config other than updating the config file. This PR fixes the behaviour. Also adds a log to highlight what HTTP method is used. Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 7510f73 commit 5ef7738

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

cmd/network.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,11 @@ func NewAPIRequest(r *Request, api string, args []string, isAsync bool) (map[str
411411
func executeRequest(r *Request, requestURL string, params url.Values) (*http.Response, error) {
412412
config.SetupContext(r.Config)
413413
if params.Has("password") || params.Has("userdata") || r.Config.Core.PostRequest {
414-
requestURL = fmt.Sprintf("%s", r.Config.ActiveProfile.URL)
414+
requestURL = r.Config.ActiveProfile.URL
415+
config.Debug("Using HTTP POST for the request: ", requestURL)
415416
return r.Client().PostForm(requestURL, params)
416417
}
418+
config.Debug("Using HTTP GET for the request: ", requestURL)
417419
req, _ := http.NewRequestWithContext(*r.Config.Context, "GET", requestURL, nil)
418420
return r.Client().Do(req)
419421
}

cmd/set.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func init() {
4545
"verifycert": {"true", "false"},
4646
"debug": {"true", "false"},
4747
"autocomplete": {"true", "false"},
48+
"postrequest": {"true", "false"},
4849
},
4950
Handle: func(r *Request) error {
5051
if len(r.Args) < 1 {

config/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type Core struct {
7676
VerifyCert bool `ini:"verifycert"`
7777
ProfileName string `ini:"profile"`
7878
AutoComplete bool `ini:"autocomplete"`
79-
PostRequest bool `ini:postrequest`
79+
PostRequest bool `ini:"postrequest"`
8080
}
8181

8282
// Config describes CLI config file and default options
@@ -401,6 +401,8 @@ func (c *Config) UpdateConfig(key string, value string, update bool) {
401401
}
402402
case "autocomplete":
403403
c.Core.AutoComplete = value == "true"
404+
case "postrequest":
405+
c.Core.PostRequest = value == "true"
404406
default:
405407
fmt.Println("Invalid option provided:", key)
406408
return

0 commit comments

Comments
 (0)