api-testing icon indicating copy to clipboard operation
api-testing copied to clipboard

Support sending HTTP request through unix socket

Open LinuxSuRen opened this issue 2 years ago • 1 comments

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)
	}
}

LinuxSuRen avatar Aug 11 '23 04:08 LinuxSuRen

This issue has been open 30 days with no activity. This will be closed in 7 days.

github-actions[bot] avatar May 12 '24 18:05 github-actions[bot]

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.

github-actions[bot] avatar May 20 '24 18:05 github-actions[bot]