api-testing
api-testing copied to clipboard
Support sending HTTP request through unix socket
Some services provide the HTTP through unix socket. For instance:
Below is a sample code:
package main
import (
"bufio"
"fmt"
"io"
"net"
)
func main() {
conn, err := net.Dial("unix", "/run/podman/podman.sock")
if err != nil {
panic(err)
}
fmt.Fprintf(conn, "GET /v4.0.0/libpod/secrets/name/json?showsecret=true HTTP/1.0\r\n\r\n")
reader := bufio.NewReader(conn)
var status string
if status, err = reader.ReadString('\n'); err == nil {
fmt.Println(status)
} else {
fmt.Println(err)
}
var header string
if header, err = reader.ReadString('\n'); err == nil {
fmt.Println(header)
} else {
fmt.Println(err)
}
var body []byte
if body, err = io.ReadAll(reader); err == nil {
fmt.Println(string(body))
} else {
fmt.Println(err)
}
}
This issue has been open 30 days with no activity. This will be closed in 7 days.
This issue has been automatically marked as stale because it hasn't had any recent activity.If you think this should still be open, or the problem still persists, just pop a reply in the comments and one of the maintainers will (try!) to follow up. Thank you for your interest and contribution to the api-testing.