fcgirt

package module
v0.0.0-...-495fa90 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 10 Imported by: 0

README

fcgirt: FastCGI http.RoundTripper

Example usage

package main

import (
	"bytes"
	"fmt"
	"github.com/johto/fcgirt"
	"net"
	"net/http"
)

func main() {
	dialer := fcgirt.DialerFunc(func () (net.Conn, error) {
		return net.Dial("unix", "/opt/api_socket")
	})
	fcgiRoundTripper := fcgirt.NewRoundTripper(dialer)
	client := &http.Client{
		Transport: fcgiRoundTripper,
	}

	postData := bytes.NewBufferString(`{"method": "Hello"}`)
	req, err := http.NewRequest("POST", "http://127.0.0.1/api/Legacy", postData)
	if err != nil {
		panic(err)
	}
	response, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	fmt.Println(response)
}

Documentation

Index

Constants

View Source
const (
	RecBeginRequest FastCGIRecordType = 1
	RecAbortRequest                   = 2
	RecEndRequest                     = 3
	RecParams                         = 4
	RecStdin                          = 5
	RecStdout                         = 6
	RecStderr                         = 7
)
View Source
const FcgiFlagKeepConn byte = 1
View Source
const FcgiRoleResponder byte = 1

only the lower byte of the role

Variables

This section is empty.

Functions

func NewParamStream

func NewParamStream(params []FastCGIParam) io.Reader

func Write14Len

func Write14Len(wr byteWriter, length int) error

Types

type Dialer

type Dialer interface {
	Dial() (net.Conn, error)
}

type DialerFunc

type DialerFunc func() (net.Conn, error)

func (DialerFunc) Dial

func (f DialerFunc) Dial() (net.Conn, error)

type FastCGIConn

type FastCGIConn struct {
	// contains filtered or unexported fields
}

func NewFastCGIConn

func NewFastCGIConn(nc net.Conn) *FastCGIConn

func (*FastCGIConn) Close

func (c *FastCGIConn) Close() error

func (*FastCGIConn) Discard

func (c *FastCGIConn) Discard(n int) error

func (*FastCGIConn) Do

func (c *FastCGIConn) Do(stdin io.Reader, params io.Reader) (*FastCGIResponse, error)

func (*FastCGIConn) ExpectRecord

func (c *FastCGIConn) ExpectRecord(typ FastCGIRecordType) (rec *FastCGIRecord, err error)

func (*FastCGIConn) Flush

func (c *FastCGIConn) Flush() error

func (*FastCGIConn) Read

func (c *FastCGIConn) Read(p []byte) (int, error)

func (*FastCGIConn) ReadRecord

func (c *FastCGIConn) ReadRecord() (*FastCGIRecord, error)

func (*FastCGIConn) Write

func (c *FastCGIConn) Write(p []byte) (int, error)

func (*FastCGIConn) Write14Len

func (c *FastCGIConn) Write14Len(length int) error

func (*FastCGIConn) WriteByte

func (c *FastCGIConn) WriteByte(b byte) error

func (*FastCGIConn) WriteRecord

func (c *FastCGIConn) WriteRecord(typ FastCGIRecordType, data []byte) error

func (*FastCGIConn) WriteStream

func (c *FastCGIConn) WriteStream(typ FastCGIRecordType, r io.Reader, bufsize int) error

func (*FastCGIConn) WriteUint16

func (c *FastCGIConn) WriteUint16(n int) error

type FastCGIParam

type FastCGIParam struct {
	Name  string
	Value []byte
}

type FastCGIRecord

type FastCGIRecord struct {
	Type    FastCGIRecordType
	Payload []byte
}

type FastCGIRecordType

type FastCGIRecordType byte

type FastCGIResponse

type FastCGIResponse struct {
	Stdout io.Reader
	Stderr io.Reader
}

type RoundTripper

type RoundTripper struct {
	http.RoundTripper
	// contains filtered or unexported fields
}

func NewRoundTripper

func NewRoundTripper(dialer Dialer) *RoundTripper

func (*RoundTripper) RoundTrip

func (rt *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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