intercept

package module
v0.0.0-...-58a4018 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2016 License: MIT Imports: 9 Imported by: 0

README

intercept

Modify HTML pages on the fly.

Problem

Sometimes I need to change webpages while requesting them for the user, in my special case I wanted to inject a script tag that loads a DOM selector library into the requested page.

Solution

This library offers an "Interceptor" that implements the http.Handler interface. Any request made to the Interceptor is then relayed to the server specified in the request and the returned page is modified before being sent back to the client.

e.g. The page you want to modify is https://golang.org/dl/. You redirect the user to https://example.com/intercept/https:/golang.org/dl/. The Interceptor establishes a connection to https://golang.org/dl/ and downloads the page. It modifies it and returns it to the user. If you use the DefaultModifier, it rewrites all (static) <a> links and <form> actions to use https://example.com/intercept.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultModifier

func DefaultModifier(baseURL *url.URL) func(*html.Node, *url.URL)

DefaultModifier creates a default DOM modifier that prefixes all links with baseURL

Types

type Interceptor

type Interceptor struct {
	Modifier []func(*html.Node, *url.URL)
	BaseURL  *url.URL
}

Interceptor enables us to inject tags into HTML pages while they are loaded

func DefaultInterceptor

func DefaultInterceptor(base string) (*Interceptor, error)

DefaultInterceptor creates a new interceptor with a DefaultModifier

func (*Interceptor) ServeHTTP

func (i *Interceptor) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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