Support for Unix domain sockets in Go HTTP clients

Overview

unixtransport Go Reference 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.

You might also like...
Fetches one or more DNS zones via AXFR and dumps in Unix hosts format for local use

axfr2hosts About axfr2hosts is a tool meant to do a DNS zone transfer in a form of AXFR transaction of one or more zones towards a single DNS server a

A simple cli tool to convert unix timestamps or human readable dates.

now A simple cli tool to convert unix timestamps or human readable dates. Install go install github.com/gloomyzerg/now Usage now #output now unix time

Simple Relay between a Unix socket and a TCP socket, and vice versa.
Simple Relay between a Unix socket and a TCP socket, and vice versa.

Simple TCP - Unix Relay simpletcpunixrelay is a program which exposes a TCP endpoint as a Unix socket and vice versa. Usecase Let's say you are runn

Golang unix-socket wrapper

Sockunx Golang unix-socket wrapper Server Running server server, e := sockunx.NewServer("/path/to/your/socks.sock", 512) if e != nil { log.Fatal(e

A Realtime API Gateway used with NATS to build REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.
A Realtime API Gateway used with NATS to build REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.

Realtime API Gateway Synchronize Your Clients Visit Resgate.io for guides, live demos, and resources. Resgate is a Go project implementing a realtime

protoc-gen-grpc-gateway-ts is a Typescript client generator for the grpc-gateway project. It generates idiomatic Typescript clients that connect the web frontend and golang backend fronted by grpc-gateway.

protoc-gen-grpc-gateway-ts protoc-gen-grpc-gateway-ts is a Typescript client generator for the grpc-gateway project. It generates idiomatic Typescript

A Wireguard VPN Server Manager and API to add and remove clients

Wireguard Manager And API A manager and API to add, remove clients as well as other features such as an auto reapplier which deletes and adds back a c

List running processes that are acting as DCE/RPC servers or clients

rpcls This project was made to assist in a larger research project. It pulls from a running process' PEB to enumerate the loaded DLLs. If a process im

A simple UDP server to make a virtual secure channel with the clients

udpsocket I made this package to make a virtual stateful connection between the client & server using the UDP protocol for a golang game server (as yo

Comments
  • Support for an analogous API to httptest.NewServer

    Support for an analogous API to httptest.NewServer

    I'm working a project where I want to support both HTTP and UNIX+HTTP transports, so I'm making use of the functionality here on the client side.

    For server testing, I came up with the following:

    // testUNIX creates a *zedhook.Client backed by a UNIX socket HTTP server which
    // returns its payload on a channel.
    func testUNIX(t *testing.T) (*zedhook.Client, <-chan zedhook.Payload) {
    	t.Helper()
    
    	pC := make(chan zedhook.Payload, 1)
    	srv := unixtestNewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    		var p zedhook.Payload
    		if err := json.NewDecoder(r.Body).Decode(&p); err != nil {
    			panicf("failed to decode JSON: %v", err)
    		}
    
    		pC <- p
    		w.WriteHeader(http.StatusNoContent)
    	}))
    	t.Cleanup(srv.Close)
    
    	c, err := zedhook.NewClient(srv.URL+"/push", nil)
    	if err != nil {
    		t.Fatalf("failed to create zedhook client: %v", err)
    	}
    
    	return c, pC
    }
    

    The API mimics the one exposed by httptest.NewServer. Would you accept a PR to add unixtransport.TestServer or similar? Thanks again!

    opened by mdlayher 2
  • Add support for abstact sockets

    Add support for abstact sockets

    This adds support for abstract unix domain sockets. They usually start with a null byte but the Go net package accepts a '@' byte prefix instead. However, the url.URL parser doesn't keep the prefix parsing the host, resulting in this information being lost.

    opened by asdine 7
Owner
Peter Bourgon
The official GitHub account of Dwayne 'The Rock' Johnson
Peter Bourgon
Event driven modular status-bar for dwm; written in Go & uses Unix sockets for signaling.

dwmstat A simple event-driven modular status-bar for dwm. It is written in Go & uses Unix sockets for signaling. The status bar is conceptualized as a

Navaz Alani 1 Dec 25, 2021
Simple forwarding a unix domain socket to a local port.

WaziApp Proxy WaziApp proxy is a simple http proxy that is intended to listen on the WaziApp unix socket /var/lib/waziapp/proxy.sock and forwards to a

Waziup 0 Nov 18, 2021
A library to simplify writing applications using TCP sockets to stream protobuff messages

BuffStreams Streaming Protocol Buffers messages over TCP in Golang What is BuffStreams? BuffStreams is a set of abstraction over TCPConns for streamin

Sean Kelly 252 Dec 13, 2022
Guilherme Biff Zarelli 3 Jun 6, 2022
Forked Version of Miekg's DNS library that recycles UDP sockets

Alternative (more granular) approach to a DNS library Less is more. Complete and usable DNS library. All Resource Records are supported, including the

null 0 Jan 20, 2022
Generate types and service clients from protobuf definitions annotated with http rules.

protoc-gen-typescript-http Generates Typescript types and service clients from protobuf definitions annotated with http rules. The generated types fol

Einride 32 Nov 22, 2022
Clients able to speak JSON over HTTP to the server

Location History Server How to run: Call the make run command. Clients able to speak JSON over HTTP to the server. There are three endpoints supported

Roman Perekhod 0 Nov 4, 2021
Transparent TLS and HTTP proxy serve and operate on all 65535 ports, with domain regex whitelist and rest api control

goshkan Transparent TLS and HTTP proxy serve & operating on all 65535 ports, with domain regex whitelist and rest api control tls and http on same por

Sina Ghaderi 11 Nov 5, 2022
A pure Unix shell script implementing ACME client protocol

An ACME Shell script: acme.sh An ACME protocol client written purely in Shell (Unix shell) language. Full ACME protocol implementation. Support ACME v

acme.sh 29.8k Jan 2, 2023
Proxy Unix applications in the terminal

cliProxy Description This wrapper binary uses pseudo-terminals on Mac and Linux to imitate TTY sessions for the hard coded binary specified by the var

Dwight Hohnstein 109 Nov 9, 2022