rendertron

package module
v0.0.0-...-888a065 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2020 License: MIT Imports: 14 Imported by: 0

README

rendertron-module

A Caddy module for Rendertron.

Rendertron is a server which runs headless Chrome and renders web pages on the fly, which can be set up to serve pages to search engines, social networks and link rendering bots.

This module checks the User-Agent header of incoming requests, and if it matches one of a configurable set of bots, proxies that request through Rendertron.

Installation

$ xcaddy build \
    --with github.com/srikrsna/rendertron

Caddyfile

redertron [<matcher>] <proxy> {
	excludeUrlPattern <pattern>
	userAgentPattern <pattern>
	timeout <timeout>
	proxy <url>
	allowedForwadedHosts <text...>
	forwardedHostHeader <text=X-Forwarded-Host>
}
Property Default Description
proxy Required Base URL of your running Rendertron proxy service.
userAgentPattern A set of known bots that benefit from pre-rendering. Full list. RegExp for matching requests by User-Agent header.
excludeUrlPattern A set of known static file extensions. Full list. RegExp for excluding requests by the path component of the URL.
injectShadyDom false Force the web components polyfills to be loaded. Read more.
timeout 11000 Millisecond timeout for the proxy request to Rendertron. If exceeded, the standard response is served (i.e. next() is called). This is not the timeout for the Rendertron server itself. See also the Rendertron timeout.
allowedForwardedHosts [] If a forwarded host header is found and matches one of the hosts in this array, then that host will be used for the request to the rendertron server instead of the actual host of the current request. This is usedful if this middleware is running on a different host which is proxied behind the actual site, and the rendertron server should request the main site. Note: For security, because the header info is untrusted, only those hosts which you explicitly allow will be forwarded, otherwise they will be ignored. Leaving this undefined or empty (the default) will disable host forwarding.
forwardedHostHeader "X-Forwarded-Host" Header used to determine the forwarded host that should be used when building the URL to be rendered. Only used if allowedForwardedHosts is not empty.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	InjectShadyDom bool
}

func (*Options) GetInjectShadyDom

func (o *Options) GetInjectShadyDom() bool

type ProxyRendertronClient

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

func NewProxyRendertronClient

func NewProxyRendertronClient(proxy string) *ProxyRendertronClient

func (*ProxyRendertronClient) Render

func (cli *ProxyRendertronClient) Render(ctx context.Context, u string, opt *Options) (*http.Response, error)

type Rendertron

type Rendertron struct {
	ExcludeUrlPattern string `json:"excludeUrlPattern,omitempty"`
	UserAgentPattern  string `json:"userAgentPattern,omitempty"`

	Timeout caddy.Duration `json:"timeout,omitempty"`
	Proxy   string         `json:"proxy"`

	AllowedForwadedHosts []string `json:"allowedForwadedHosts,omitempty"`
	ForwardedHostHeader  string   `json:"forwardedHostHeader,omitempty"`
	// contains filtered or unexported fields
}

func (Rendertron) CaddyModule

func (Rendertron) CaddyModule() caddy.ModuleInfo

func (*Rendertron) Provision

func (c *Rendertron) Provision(ctx caddy.Context) error

func (*Rendertron) ServeHTTP

func (c *Rendertron) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

func (*Rendertron) UnmarshalCaddyfile

func (c *Rendertron) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler. Syntax:

rendertron [<matcher>] <url> {
	excludeUrlPattern <pattern>
	userAgentPattern <pattern>
	timeout <timeout>
	proxy <url>
	allowedForwadedHosts <text...>
	forwardedHostHeader <text=X-Forwarded-Host>
}

func (*Rendertron) Validate

func (c *Rendertron) Validate() error

type RendertronClient

type RendertronClient interface {
	Render(ctx context.Context, u string, opt *Options) (*http.Response, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL