fastcgi

package module
v0.0.0-...-abdc162 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

README

下载

go get gitee.com/xqhero/fastcgi

使用

package main

import (
	"fmt"
	"gitee.com/xqhero/fastcgi"
	"io/ioutil"
	"net/http"
)

func main() {
	http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
		bytes, _ := ioutil.ReadFile("./index.html")
		writer.Write(bytes)
	})
	server := fastcgi.NewFcgiServer("127.0.0.1:9000", nil)
	err := server.Start()
	if err != nil {
		fmt.Println("fcgiserver start error")
	}
}


文档说明

https://wiki.xqhero.com/docs/tcp-ip

Documentation

Index

Constants

View Source
const (
	MAXCONTENT = 65535
	MAXPAD     = 255
)
定义包的大小常量

contentlength用2个字节表示则最大为65535 paddinglenth 用1个字节表示则最大为255

View Source
const (
	FCGI_BEGIN_REQUEST     rctype = 1
	FCGI_ABORT_REQUEST     rctype = 2
	FCGI_END_REQUEST       rctype = 3
	FCGI_PARAMS            rctype = 4
	FCGI_STDIN             rctype = 5
	FCGI_STDOUT            rctype = 6
	FCGI_STDERR            rctype = 7
	FCGI_DATA              rctype = 8
	FCGI_GET_VALUES        rctype = 9
	FCGI_GET_VALUES_RESULT rctype = 10
	FCGI_UNKNOWN_TYPE      rctype = 11
)

消息头类型定义

View Source
const (
	ROLE_FCGI_RESPONSE   = iota + 1 // 响应器
	ROLE_FCGI_AUTHORIZER            // 授权器
	ROLE_FCGI_FILTER                // 过滤器
)

角色

View Source
const (
	FCGI_REQUEST_COMPLETE = iota
	FCGI_CANT_MPX_CONN
	FCGI_OVERLOADED
	FCGI_UNKNOW_ROLE
)

请求完成描述

Variables

View Source
var ErrConnClosed = errors.New("fcgi: connection to web server closed")

Functions

func RequestFromMap

func RequestFromMap(params map[string]string) (*http.Request, error)

Types

type Conn

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

func (*Conn) Close

func (c *Conn) Close() error

type ConnChild

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

connChild

func NewConnChild

func NewConnChild(conn io.ReadWriteCloser, handler http.Handler) *ConnChild

func (*ConnChild) Serve

func (c *ConnChild) Serve()

type FCGI_BeginRequestBody

type FCGI_BeginRequestBody struct {
	Role     uint16   // 角色,2字节 对应 RoleB1 RoleB0
	Flags    uint8    // 是否保持连接标记
	Reserved [5]uint8 // 保留字段
}

ftype=1 消息体

type FCGI_Header

type FCGI_Header struct {
	Version       uint8  // 版本
	Ftype         rctype // 类型
	RequestId     uint16 // 请求ID, 两个字节 对应 RequestId1 和 RequestId0
	ContentLength uint16 // 内容长度,两个字节 对应 ContentLengthB1 和 ContentLengthB0
	PaddingLength uint8  // 填充字节的长度
	Reserved      uint8  // 保留字节
}

消息头结构体,8字节

type FcgiServer

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

FcgiServer

func NewFcgiServer

func NewFcgiServer(addr string, handler http.Handler) *FcgiServer

func (*FcgiServer) Start

func (srv *FcgiServer) Start() error

type Record

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

record

type Request

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

请求结构体

func NewRequest

func NewRequest(reqId uint16, flags uint8) *Request

构造新请求

func (*Request) ParseParams

func (req *Request) ParseParams()

解析key-value 0x220x33namea 0x220x33namea

type Response

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

实现 ResponseWriter 接口

func NewResponse

func NewResponse(c *ConnChild, req *Request) *Response

func (*Response) Close

func (r *Response) Close() error

func (*Response) Flush

func (r *Response) Flush()

func (*Response) Header

func (resp *Response) Header() http.Header

func (*Response) Write

func (resp *Response) Write(p []byte) (int, error)

func (*Response) WriteHeader

func (resp *Response) WriteHeader(statusCode int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳