diff options
Diffstat (limited to 'docs/http')
-rw-r--r-- | docs/http/headers.md | 37 | ||||
-rw-r--r-- | docs/http/https.md | 71 | ||||
-rw-r--r-- | docs/http/middleware.md | 77 | ||||
-rw-r--r-- | docs/http/static.md | 56 |
4 files changed, 0 insertions, 241 deletions
diff --git a/docs/http/headers.md b/docs/http/headers.md deleted file mode 100644 index 97bc0cb3..00000000 --- a/docs/http/headers.md +++ /dev/null @@ -1,37 +0,0 @@ -# Headers and CORS -RoadRunner can automatically set up request/response headers and control CORS for your application. - -### CORS -To enable CORS headers add the following section to your configuration. - -```yaml -http: - address: 127.0.0.1:44933 - middleware: ["headers"] - # ... - headers: - cors: - allowed_origin: "*" - allowed_headers: "*" - allowed_methods: "GET,POST,PUT,DELETE" - allow_credentials: true - exposed_headers: "Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma" - max_age: 600 -``` - -> Make sure to declare "headers" middleware. - -### Custom headers for Response or Request -You can control additional headers to be set for outgoing responses and headers to be added to the request sent to your application. -```yaml -http: - # ... - headers: - # Automatically add headers to every request passed to PHP. - request: - Example-Request-Header: "Value" - - # Automatically add headers to every response. - response: - X-Powered-By: "RoadRunner" -``` diff --git a/docs/http/https.md b/docs/http/https.md deleted file mode 100644 index e586d18c..00000000 --- a/docs/http/https.md +++ /dev/null @@ -1,71 +0,0 @@ -# HTTPS and HTTP/2 - -You can enable HTTPS and HTTP2 support by adding `ssl` section into `http` config. - -```yaml -http: - # host and port separated by semicolon - address: 127.0.0.1:8080 - - ssl: - # host and port separated by semicolon (default :443) - address: :8892 - redirect: false - cert: fixtures/server.crt - key: fixtures/server.key - root_ca: root.crt - - # optional support for http2 - http2: - h2c: false - max_concurrent_streams: 128 -``` - -### Redirecting HTTP to HTTPS - -To enable an automatic redirect from `http://` to `https://` set `redirect` option to `true` (disabled by default). - -### HTTP/2 Push Resources - -RoadRunner support [HTTP/2 push](https://en.wikipedia.org/wiki/HTTP/2_Server_Push) via virtual headers provided by PHP -response. - -```php -return $response->withAddedHeader('http2-push', '/test.js'); -``` - -Note that the path of the resource must be related to the public application directory and must include `/` at the -beginning. - -> Please note, HTTP2 push only works under HTTPS with `static` service enabled. - -## H2C - -You can enable HTTP/2 support over non-encrypted TCP connection using H2C: - -```yaml -http: - http2.h2c: true -``` - -### FastCGI - -There is FastCGI frontend support inside the HTTP module, you can enable it (disabled by default): - -```yaml -http: - # HTTP service provides FastCGI as frontend - fcgi: - # FastCGI connection DSN. Supported TCP and Unix sockets. - address: tcp://0.0.0.0:6920 -``` - -### Root certificate authority support - -Root CA supported by the option in .rr.yaml - -```yaml -http: - ssl: - root_ca: root.crt -```
\ No newline at end of file diff --git a/docs/http/middleware.md b/docs/http/middleware.md deleted file mode 100644 index dd05e6e6..00000000 --- a/docs/http/middleware.md +++ /dev/null @@ -1,77 +0,0 @@ -# HTTP Middleware - -RoadRunner HTTP server uses default Golang middleware model which allows you to extend it using custom or -community-driven middleware. The simplest service with middleware registration would look like: - -```golang -package middleware - -import ( - "net/http" -) - -const PluginName = "middleware" - -type Plugin struct{} - -// to declare plugin -func (g *Plugin) Init() error { - return nil -} - -func (g *Plugin) Middleware(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // do something - // ... - // continue request through the middleware pipeline - next.ServeHTTP(w, r) - }) -} - -// Middleware/plugin name. -func (g *Plugin) Name() string { - return PluginName -} -``` - -> Middleware must correspond to the following [interface](https://github.com/spiral/roadrunner/blob/master/plugins/http/plugin.go#L37) and be named. - -We have to register this service after in the [`internal/container/plugin.go`](https://github.com/spiral/roadrunner-binary/blob/master/internal/container/plugins.go#L31) file in order to properly resolve dependency: - -```golang -import ( - "middleware" -) - -func Plugins() []interface{} { - return []interface{}{ - // ... - - // middleware - &middleware.Plugin{}, - - // ... - } -``` - -You should also make sure you configure the middleware to be used via the [config or the command line](https://roadrunner.dev/docs/intro-config) otherwise the plugin will be loaded but the middleware will not be used with incoming requests. - -```yaml -http: - # provide the name of the plugin as provided by the plugin in the example's case, "middleware" - middleware: [ "middleware" ] -``` - -### PSR7 Attributes - -You can safely pass values to `ServerRequestInterface->getAttributes()` using [attributes](https://github.com/spiral/roadrunner/blob/master/plugins/http/attributes/attributes.go) package: - -```golang -func (s *Service) middleware(next http.HandlerFunc) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - r = attributes.Init(r) - attributes.Set(r, "key", "value") - next(w, r) - } -} -``` diff --git a/docs/http/static.md b/docs/http/static.md deleted file mode 100644 index 617c3991..00000000 --- a/docs/http/static.md +++ /dev/null @@ -1,56 +0,0 @@ -# Serving static content - -It is possible to serve static content using RoadRunner. - -## Enable HTTP Middleware - -To enable static content serving use the configuration inside the http section: - -```yaml -http: - # host and port separated by semicolon - address: 127.0.0.1:44933 - # ... - static: - dir: "." - forbid: [""] - allow: [".txt", ".php"] - calculate_etag: false - weak: false - request: - input: "custom-header" - response: - output: "output-header" -``` - -Where: - -1. `dir`: path to the directory. -3. `forbid`: file extensions that should not be served. -4. `allow`: file extensions which should be served (empty - serve all except forbidden). If extension presented in both (allow and forbid) hashmaps - that treated as we should forbid file extension. -5. `calculate_etag`: turn on etag computation for the static file. -6. `weak`: use a weak generator (/W), it uses only filename to generate a CRC32 sum. If false - all file content used to generate CRC32 sum. -7. `request/response`: custom headers for the static files. - -To combine static content with other middleware, use the following sequence (static will always be the last in the row, file server will apply headers and gzip plugins): - -```yaml -http: - # host and port separated by semicolon - address: 127.0.0.1:44933 - # ... - middleware: [ "headers", "gzip" ] - # ... - headers: - # ... - static: - dir: "." - forbid: [""] - allow: [".txt", ".php"] - calculate_etag: false - weak: false - request: - input: "custom-header" - response: - output: "output-header" -``` |