Documentation
¶
Index ¶
- Constants
- type Config
- type ErrorEvent
- type FCGIConfig
- type FileUpload
- type HTTP2Config
- type Handler
- type Request
- type Response
- type ResponseEvent
- type SSLConfig
- type Service
- func (s *Service) AddListener(l func(event int, ctx interface{}))
- func (s *Service) AddMiddleware(m middleware)
- func (s *Service) Attach(w roadrunner.Controller)
- func (s *Service) Init(cfg *Config, r *rpc.Service, e env.Environment, log *logrus.Logger) (bool, error)
- func (s *Service) ProduceCommands(producer roadrunner.CommandProducer)
- func (s *Service) Serve() error
- func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Service) Server() *roadrunner.Server
- func (s *Service) Stop()
- type Uploads
- type UploadsConfig
- type WorkerList
Constants ¶
const ( // EventResponse thrown after the request been processed. See ErrorEvent as payload. EventResponse = iota + 500 // EventError thrown on any non job error provided by road runner server. EventError )
const ( // ID contains default service name. ID = "http" // EventInitSSL thrown at moment of https initialization. SSL server passed as context. EventInitSSL = 750 )
const ( // UploadErrorOK - no error, the file uploaded with success. UploadErrorOK = 0 // UploadErrorNoFile - no file was uploaded. UploadErrorNoFile = 4 // UploadErrorNoTmpDir - missing a temporary folder. UploadErrorNoTmpDir = 5 // UploadErrorCantWrite - failed to write file to disk. UploadErrorCantWrite = 6 // UploadErrorExtension - forbidden file extension. UploadErrorExtension = 7 )
const MaxLevel = 127
MaxLevel defines maximum tree depth for incoming request data and files.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// AppErrorCode is error code for the application errors (default 500)
AppErrorCode uint64
// Error code for the RR pool or worker errors
InternalErrorCode uint64
// Port and port to handle as http server.
Address string
// SSL defines https server options.
SSL SSLConfig
// FCGI configuration. You can use FastCGI without HTTP server.
FCGI *FCGIConfig
// HTTP2 configuration
HTTP2 *HTTP2Config
// MaxRequestSize specified max size for payload body in megabytes, set 0 to unlimited.
MaxRequestSize int64
// TrustedSubnets declare IP subnets which are allowed to set ip using X-Real-Ip and X-Forwarded-For
TrustedSubnets []string
// Uploads configures uploads configuration.
Uploads *UploadsConfig
// Workers configures rr server and worker pool.
Workers *roadrunner.ServerConfig
// contains filtered or unexported fields
}
Config configures RoadRunner HTTP server.
func (*Config) EnableFCGI ¶ added in v1.4.4
EnableFCGI is true when FastCGI server must be enabled.
func (*Config) EnableHTTP ¶ added in v1.4.4
EnableHTTP is true when http server must run.
func (*Config) EnableHTTP2 ¶ added in v1.4.4
EnableHTTP2 when HTTP/2 extension must be enabled (only with TSL).
func (*Config) EnableTLS ¶ added in v1.2.4
EnableTLS returns true if rr must listen TLS connections.
func (*Config) Hydrate ¶ added in v1.1.0
Hydrate must populate Config values using given Config source. Must return error if Config is not valid.
type ErrorEvent ¶ added in v1.1.0
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 ¶ added in v1.3.0
func (e *ErrorEvent) Elapsed() time.Duration
Elapsed returns duration of the invocation.
type FCGIConfig ¶ added in v1.4.4
type FCGIConfig struct {
// Address and port to handle as http server.
Address string
}
FCGIConfig for FastCGI server.
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 *UploadsConfig) (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 HTTP2Config ¶ added in v1.4.4
type HTTP2Config struct {
// Enable or disable HTTP/2 extension, default enable.
Enabled bool
// H2C enables HTTP/2 over TCP
H2C bool
// MaxConcurrentStreams defaults to 128.
MaxConcurrentStreams uint32
}
HTTP2Config HTTP/2 server customizations.
func (*HTTP2Config) InitDefaults ¶ added in v1.4.4
func (cfg *HTTP2Config) InitDefaults() error
InitDefaults sets default values for HTTP/2 configuration.
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).
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 ¶
func NewRequest(r *http.Request, cfg *UploadsConfig) (req *Request, err error)
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"`
// contains filtered or unexported fields
}
Response handles PSR7 response logic.
func NewResponse ¶
func NewResponse(p *roadrunner.Payload) (*Response, error)
NewResponse creates new response based on given rr payload.
type ResponseEvent ¶ added in v1.1.0
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 ¶ added in v1.3.0
func (e *ResponseEvent) Elapsed() time.Duration
Elapsed returns duration of the invocation.
type SSLConfig ¶ added in v1.2.4
type SSLConfig struct {
// Port to listen as HTTPS server, defaults to 443.
Port int
// Redirect when enabled forces all http connections to switch to https.
Redirect bool
// Key defined private server key.
Key string
// Cert is https certificate.
Cert string
// Root CA file
RootCA string
}
SSLConfig defines https server configuration.
type Service ¶
Service manages rr, http servers.
func (*Service) AddListener ¶
AddListener attaches server event controller.
func (*Service) AddMiddleware ¶
func (s *Service) AddMiddleware(m middleware)
AddMiddleware adds new net/http mdwr.
func (*Service) Attach ¶ added in v1.4.0
func (s *Service) Attach(w roadrunner.Controller)
Attach attaches controller. Currently only one controller is supported.
func (*Service) Init ¶
func (s *Service) Init(cfg *Config, r *rpc.Service, e env.Environment, log *logrus.Logger) (bool, error)
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 (*Service) ProduceCommands ¶ added in v1.5.3
func (s *Service) ProduceCommands(producer roadrunner.CommandProducer)
ProduceCommands changes the default command generator method
func (*Service) ServeHTTP ¶
func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles connection using set of middleware and rr PSR-7 server.
func (*Service) Server ¶ added in v1.4.0
func (s *Service) Server() *roadrunner.Server
Server returns associated rr server (if any).
type Uploads ¶
type Uploads struct {
// contains filtered or unexported fields
}
Uploads tree manages uploaded files tree and temporary files.
func (*Uploads) MarshalJSON ¶
MarshalJSON marshal tree tree into JSON.
type UploadsConfig ¶
type UploadsConfig struct {
// Dir contains name of directory to control access to.
Dir string
// Forbid specifies list of file extensions which are forbidden for access.
// Example: .php, .exe, .bat, .htaccess and etc.
Forbid []string
}
UploadsConfig describes file location and controls access to them.
func (*UploadsConfig) Forbids ¶
func (cfg *UploadsConfig) Forbids(filename string) bool
Forbids must return true if file extension is not allowed for the upload.
func (*UploadsConfig) InitDefaults ¶ added in v1.2.2
func (cfg *UploadsConfig) InitDefaults() error
InitDefaults sets missing values to their default values.
func (*UploadsConfig) TmpDir ¶
func (cfg *UploadsConfig) TmpDir() string
TmpDir returns temporary directory.
type WorkerList ¶
WorkerList contains list of workers.