首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

net/http/cgi

  • import "net/http/cgi"
  • 概述
  • 索引

概述

cgi包实现了 RFC 3875 中规定的 CGI(通用网关接口)。

请注意,使用 CGI 意味着启动一个新的进程来处理每个请求,这通常比使用长时间运行的服务器效率低。此软件包主要用于与现有系统兼容。

索引

  • func Request() (*http.Request, error)
  • func RequestFromMap(params map[string]string) (*http.Request, error)
  • func Serve(handler http.Handler) error
  • type Handler
  • func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

文件包

func Request() (*http.Request, error)

请求返回当前环境中表示的 HTTP 请求。这假定当前程序由 CGI 环境中的 Web 服务器运行。如果适用,填充返回的请求的正文。

func RequestFromMap(显示源文件)

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

RequestFromMap从CGI变量创建一个http.Request。返回的请求的正文字段未填充。

func Serve(handler http.Handler) error

Serve在当前活动的CGI请求上执行提供的Handler,如果有的话。如果没有当前的CGI环境,则返回错误。提供的处理程序可能无法使用http.DefaultServeMux。

Handler在具有CGI环境的子进程中运行可执行文件。

type Handler struct {
        Path string // path to the CGI executable
        Root string // root URI prefix of handler or empty for "/"

        // Dir specifies the CGI executable's working directory.
        // If Dir is empty, the base directory of Path is used.
        // If Path has no base directory, the current working
        // directory is used.
        Dir string

        Env        []string    // extra environment variables to set, if any, as "key=value"
        InheritEnv []string    // environment variables to inherit from host, as "key"
        Logger     *log.Logger // optional log for errors or nil to use log.Print
        Args       []string    // optional arguments to pass to child process
        Stderr     io.Writer   // optional stderr for the child process; nil means os.Stderr

        // PathLocationHandler specifies the root http Handler that
        // should handle internal redirects when the CGI process
        // returns a Location header value starting with a "/", as
        // specified in RFC 3875 § 6.3.2. This will likely be
        // http.DefaultServeMux.
        //
        // If nil, a CGI response with a local URI path is instead sent
        // back to the client and not redirected internally.
        PathLocationHandler http.Handler
}

func (*Handler) ServeHTTP(显示源文件)

func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

扫码关注腾讯云开发者

领取腾讯云代金券