parser

package
v0.0.0-...-4b869d4 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2018 License: LGPL-3.0 Imports: 11 Imported by: 1

README

Build Status MiddlewareVet GoDoc

Parser

Auto generate Push Frames / Link Headers from html response bodies


Note :

Not ready for production

  • has not been optimized
  • few tests have been written
  • might break everything. might be awesome

How it works :

parser reads the first 1024 bytes from html response bodies. For H2 connections and Push capable clients it will generate Push Frames. For H1 connections or Push incapable clients it will send Link Headers. If a preload link was also found in the html the asset is ignored. Only one preload method should be used and this pkg should not alter the response body.


Stuff it does :
  • generates H2 Push frames / Link Headers based on html bodies
  • has a cache option (to only read from the body once)
  • respects nopush
  • is compatible with HTTP1.1 requests
  • plays nice when behind a proxy (No Pushes when X-Forwarded-For is set)

example :

package main

import (
	"net/http"

	"github.com/romainmenke/pusher/link"
)

func main() {

	http.Handle("/",
		parser.Handler(
				YourHandlerHere
			),
			parser.WithCache(),
			parser.CacheDuration(time.Hour*100000),
		),
	)

}

The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheDuration

func CacheDuration(d time.Duration) func(*settings)

CacheDuration sets the cache duration

func Handler

func Handler(handler http.Handler, options ...Option) http.Handler

Handler wraps an http.Handler reading the response body and setting Link Headers or generating Pushes

func WithCache

func WithCache() func(*settings)

WithCache makes the Handler cache which assets were pushed/preloaded after parsing the html response once. Useful html files that don't change after server start

Types

type Option

type Option func(*settings)

Option -> Functional Options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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