unixtransport

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 7 Imported by: 12

README

unixtransport Go Reference Latest Release Tests

This package adds support for Unix domain sockets in Go HTTP clients.

t := &http.Transport{...}

unixtransport.Register(t)

client := &http.Client{Transport: t}

Now you can make requests with URLs like this:

resp, err := client.Get("https+unix:///path/to/socket:/request/path?a=b")

Use scheme http+unix or https+unix.

Inspiration taken from, and thanks given to, both tv42/httpunix and agorman/httpunix.

Documentation

Overview

package unixtransport allows HTTP client requests to Unix sockets.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(t *http.Transport)

Register adds a protocol handler to the provided transport that can serve requests to Unix domain sockets via the "http+unix" or "https+unix" schemes. Request URLs should have the following form:

https+unix:///path/to/socket:/request/path?query=val&...

The registered transport is based on a clone of the provided transport, and so uses the same configuration: timeouts, TLS settings, and so on. Connection pooling should also work as normal. One caveat: only the DialContext and DialTLSContext dialers are respected; the Dial and DialTLS dialers are explicitly removed and ignored. Any configured Proxy is also discarded.

Example (Custom)
package main

import (
	"net/http"

	"github.com/peterbourgon/unixtransport"
)

func main() {
	t := &http.Transport{
		// ...
	}

	unixtransport.Register(t)

	c := &http.Client{
		Transport: t,
		// ...
	}

	c.Get("https+unix:///tmp/my.sock")
}
Output:

Example (Default)
package main

import (
	"net/http"

	"github.com/peterbourgon/unixtransport"
)

func main() {
	// Register the "http+unix" and "https+unix" protocols in the default client transport.
	unixtransport.Register(http.DefaultTransport.(*http.Transport))

	// This will issue a GET request to an HTTP server listening at /tmp/my.sock.
	// Note the three '/' characters between 'http+unix:' and 'tmp'.
	http.Get("http+unix:///tmp/my.sock")

	// This shows how to include a request path and query.
	http.Get("http+unix:///tmp/my.sock:/users/123?q=abc")
}
Output:

Types

This section is empty.

Directories

Path Synopsis
package unixproxy provides an EXPERIMENTAL reverse proxy to Unix sockets.
package unixproxy provides an EXPERIMENTAL reverse proxy to Unix sockets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL