Documentation ¶
Index ¶
- Constants
- Variables
- func FetchIndexes(s string) []string
- type ErrorEvent
- type FileUpload
- type Handler
- type Middleware
- type Plugin
- func (s *Plugin) AddMiddleware(name endure.Named, m Middleware)
- func (s *Plugin) Collects() []interface{}
- func (s *Plugin) Init(cfg config.Configurer, rrLogger logger.Logger, server server.Server) error
- func (s *Plugin) Name() string
- func (s *Plugin) Ready() status.Status
- func (s *Plugin) Reset() error
- func (s *Plugin) Serve() chan error
- func (s *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Plugin) Status() status.Status
- func (s *Plugin) Stop() error
- func (s *Plugin) Workers() []process.State
- type Request
- type Response
- type ResponseEvent
- type Uploads
Constants ¶
const ( // PluginName declares plugin name. PluginName = "http" // RR_HTTP env variable key (internal) if the HTTP presents RR_MODE = "RR_MODE" //nolint:golint,stylecheck // HTTPS_SCHEME HTTPS_SCHEME = "https" //nolint:golint,stylecheck )
const ( // UploadErrorOK - no error, the file uploaded with success. UploadErrorOK = 0 // UploadErrorNoFile - no file was uploaded. UploadErrorNoFile = 4 // UploadErrorNoTmpDir - missing a temporary folder. UploadErrorNoTmpDir = 6 // UploadErrorCantWrite - failed to write file to disk. UploadErrorCantWrite = 7 // UploadErrorExtension - forbidden file extension. UploadErrorExtension = 8 )
const MB uint64 = 1024 * 1024
MB is 1024 bytes
const MaxLevel = 127
MaxLevel defines maximum tree depth for incoming request data and files.
Variables ¶
var TrailerHeaderKey = http.CanonicalHeaderKey("trailer")
TrailerHeaderKey http header key
Functions ¶
func FetchIndexes ¶
FetchIndexes parses input name and splits it into separate indexes list.
Types ¶
type ErrorEvent ¶
type ErrorEvent struct { // Request contains client request, must not be stored. Request *http.Request // Error - associated error, if any. Error error // contains filtered or unexported fields }
ErrorEvent represents singular http error event.
func (*ErrorEvent) Elapsed ¶
func (e *ErrorEvent) Elapsed() time.Duration
Elapsed returns duration of the invocation.
type FileUpload ¶
type FileUpload struct { // ID contains filename specified by the client. Name string `json:"name"` // Mime contains mime-type provided by the client. Mime string `json:"mime"` // Size of the uploaded file. Size int64 `json:"size"` // Error indicates file upload error (if any). See http://php.net/manual/en/features.file-upload.errors.php Error int `json:"error"` // TempFilename points to temporary file location. TempFilename string `json:"tmpName"` // contains filtered or unexported fields }
FileUpload represents singular file NewUpload.
func NewUpload ¶
func NewUpload(f *multipart.FileHeader) *FileUpload
NewUpload wraps net/http upload into PRS-7 compatible structure.
func (*FileUpload) Open ¶
func (f *FileUpload) Open(cfg config.Uploads) (err error)
Open moves file content into temporary file available for PHP. NOTE: There is 2 deferred functions, and in case of getting 2 errors from both functions error from close of temp file would be overwritten by error from the main file STACK DEFER FILE CLOSE (2) DEFER TMP CLOSE (1)
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves http connections to underlying PHP application using PSR-7 protocol. Context will include request headers, parsed files and query, payload will include parsed form dataTree (if any).
func NewHandler ¶
func NewHandler(maxReqSize uint64, uploads config.Uploads, trusted config.Cidrs, pool pool.Pool) (*Handler, error)
NewHandler return handle interface implementation
func (*Handler) AddListener ¶
AddListener attaches handler event controller.
type Middleware ¶
type Middleware interface {
Middleware(f http.Handler) http.HandlerFunc
}
Middleware interface
type Plugin ¶
Plugin manages pool, http servers. The main http plugin structure
func (*Plugin) AddMiddleware ¶
func (s *Plugin) AddMiddleware(name endure.Named, m Middleware)
AddMiddleware is base requirement for the middleware (name and Middleware)
func (*Plugin) Collects ¶
func (s *Plugin) Collects() []interface{}
Collects collecting http middlewares
func (*Plugin) Init ¶
Init must return configure svc and return true if svc hasStatus enabled. Must return error in case of misconfiguration. Services must not be used without proper configuration pushed first.
func (*Plugin) Reset ¶
Reset destroys the old pool and replaces it with new one, waiting for old pool to die
func (*Plugin) ServeHTTP ¶
func (s *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles connection using set of middleware and pool PSR-7 server.
type Request ¶
type Request struct { // RemoteAddr contains ip address of client, make sure to check X-Real-Ip and X-Forwarded-For for real client address. RemoteAddr string `json:"remoteAddr"` // Protocol includes HTTP protocol version. Protocol string `json:"protocol"` // Method contains name of HTTP method used for the request. Method string `json:"method"` // URI contains full request URI with scheme and query. URI string `json:"uri"` // Header contains list of request headers. Header http.Header `json:"headers"` // Cookies contains list of request cookies. Cookies map[string]string `json:"cookies"` // RawQuery contains non parsed query string (to be parsed on php end). RawQuery string `json:"rawQuery"` // Parsed indicates that request body has been parsed on RR end. Parsed bool `json:"parsed"` // Uploads contains list of uploaded files, their names, sized and associations with temporary files. Uploads *Uploads `json:"uploads"` // Attributes can be set by chained mdwr to safely pass value from Golang to PHP. See: GetAttribute, SetAttribute functions. Attributes map[string]interface{} `json:"attributes"` // contains filtered or unexported fields }
Request maps net/http requests to PSR7 compatible structure and managed state of temporary uploaded files.
func NewRequest ¶
NewRequest creates new PSR7 compatible request using net/http request.
type Response ¶
type Response struct { // Status contains response status. Status int `json:"status"` // Header contains list of response headers. Headers map[string][]string `json:"headers"` // associated Body payload. Body interface{} sync.Mutex }
Response handles PSR7 response logic.
func NewResponse ¶
NewResponse creates new response based on given pool payload.
type ResponseEvent ¶
type ResponseEvent struct { // Request contains client request, must not be stored. Request *Request // Response contains service response. Response *Response // contains filtered or unexported fields }
ResponseEvent represents singular http response event.
func (*ResponseEvent) Elapsed ¶
func (e *ResponseEvent) Elapsed() time.Duration
Elapsed returns duration of the invocation.