Skip to content

Commit 5bb7214

Browse files
Add request helper command to send requests over DevPod network
1 parent 8f9b952 commit 5bb7214

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

cmd/helper/helper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ func NewHelperCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
3535
helperCmd.AddCommand(NewFleetServerCmd(globalFlags))
3636
helperCmd.AddCommand(NewDockerCredentialsHelperCmd(globalFlags))
3737
helperCmd.AddCommand(NewGetImageCmd(globalFlags))
38+
helperCmd.AddCommand(requestCmd)
3839
return helperCmd
3940
}

cmd/helper/request.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package helper
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"log"
7+
8+
"github.com/loft-sh/devpod/pkg/daemon/workspace/network"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var requestCmd = &cobra.Command{
13+
Use: "request [path]",
14+
Short: "Send an HTTP request to the specified path via the DevPod network",
15+
Args: cobra.ExactArgs(1),
16+
Run: func(cmd *cobra.Command, args []string) {
17+
path := args[0]
18+
19+
client := network.GetHTTPClient()
20+
21+
url := fmt.Sprintf("http://%s", path)
22+
log.Printf("Sending request to %s via DevPod network", url)
23+
24+
resp, err := client.Get(url)
25+
if err != nil {
26+
log.Fatalf("HTTP request error: %v", err)
27+
}
28+
defer resp.Body.Close()
29+
30+
body, err := io.ReadAll(resp.Body)
31+
if err != nil {
32+
log.Fatalf("Error reading response: %v", err)
33+
}
34+
fmt.Printf("Response:\n%s\n", body)
35+
},
36+
}

0 commit comments

Comments
 (0)