• Stars
    star
    108
  • Rank 321,259 (Top 7 %)
  • Language
    Go
  • License
    MIT License
  • Created about 8 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cache aware server push (CASPer) in Golang

go-casper Go Documentation Travis MIT License

Package go-casper is Golang implementation of H2O's CASPer (cache-aware server-push).

Go 1.8 is going to support HTTP/2 server push. Server push allows us to send resources like CSS or JavaScript files before the client asks (so we can expect faster page rendering). As described on this post or this issue, one of the important things to use server push is to know when to push. Since it's waste of the network bandwidth (and cause negative effects on response time), you should avoid to push the asset which has already been cached by the client.

To solve these problem, H2O, a server that provides full advantage of HTTP/2 features, introduces CASPer. CASPer maintains a fingerprint of the browser caches (Golomb-compressed bloom filter) as a cookie, and cancels server-push if the fingerprint indicates the client is known to be in possession of the contents.

go-casper implements H2O's CASPer and provides similar fucntinality in any golang http server. It wraps go's standard server push method (see "HTTP/2 Server Push ยท Go, the unwritten parts" if you don't how to use it) and maintains a fingerprint of browser caches and decides to push or cancel. The fingerprint is generated by using golomb-coded sets (a compressed encoding of Bloom filter).

The full documentation is available on Godoc.

NOTE1: This project is still a proof of concept and still under heavy implementation. API may be changed in future and documentaion is incomplete. This code should not be run in production. Comments are all welcome!

NOTE2: There is a draft by H2O author which defines a HTTP/2 frame type to allow clients to inform the server of their cache's contents ๐Ÿ‘ This pacakage can be replace with it in future.

Example

Below is a simple example of usage.

// Initialize casper with false-positive probability 
// 1/64 and number of assets 10.
pusher := casper.New(1<<6, 10)

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {    
    
    // Execute cache aware server push. 
    // 
    // In this example, it generates a fingerprint "JA" and set it
    // as "x-go-casper" cookie value.
    // 
    // If you access this handler first time, it runs server-push.
    // But from next time, with same client, it cancels pushing since 
    // cookie indicates asset has already been cached by the client.
    if _, err := pusher.Push(w, r, []string{"/static/example.js"}, nil); err != nil {
        log.Printf("[ERROR] Failed to push assets: %s", err)
    }

    // ...
})

You can find the complete example here.

More Repositories

1

ghr

Upload multiple artifacts to GitHub Release in parallel
Go
1,234
star
2

gcli

The easy way to build Golang command-line application.
Go
921
star
3

go-httpstat

Tracing golang HTTP request latency
Go
421
star
4

docker-alias

My Docker alias and functions
Shell
372
star
5

go-slack-interactive

Sample slack bot which uses slack interactive message (button & menue) written in Golang
Go
306
star
6

gotests

[Archived] A tool to generate Go test functions from the given source code like gofmt
Go
264
star
7

go-input

Go package for ideal tty prompt
Go
253
star
8

awesome-container

A curated list of awesome container technologies and services
174
star
9

go-latest

Simple way to check version is latest or not from various sources in Golang
Go
136
star
10

license

Generate LICENSE file you want
Go
117
star
11

go-binary-only-package

Sample of Go1.7 Binary-Only Packages
Go
79
star
12

dockerfile-rbenv

Dockerfile to build Image which is installed muliple versions of ruby
76
star
13

go-gitconfig

Use gitconfig values in Golang.
Go
59
star
14

boot2kubernetes

Run single node kubernetes cluseter in one command
Go
37
star
15

dockerfile-gox

Docekerfile for gox, cross-compiling golang project parallelly
Dockerfile
36
star
16

dotfiles

@tcnksm does dotfiles
Shell
30
star
17

waypoint-plugin-kustomize

Experimental implementation of waypoint plugin for kustomize
Go
30
star
18

talks

@tcnksm talks at conference or on Podcast
Go
27
star
19

rbdock

Generate Dockerfile for Ruby or Rails, Sinatra.
Ruby
24
star
20

deeeet.com

@tcnksm writes blog
SCSS
24
star
21

dutyme

Assign PagerDuty on-call to you while operation
Go
23
star
22

go-algorithms

Algorithms and data structure by golang
Go
21
star
23

go-distributed-tracing

Sample kubernetes config and golang apps to try distributed tracing with Stackdriver
Go
20
star
24

vagrant-digitalocean-coreos

Create CoreOS cluster on DigitalOcean by Vagrant
19
star
25

go-crypto

Play with golang crypto package
Go
19
star
26

go-holidayjp

Go package for detecting holiday in Japan
Go
15
star
27

gox-server

Golang cross-compile on Heroku
Go
15
star
28

docker-link-pattern

Docker container link patterns
Ruby
13
star
29

alexa-irkit-ac

A sample implementation of custom Alexa Smart Home Skill by Golang
Go
12
star
30

sudo-controller

Kubernetes controller which allows you to create time bound role binding with approval.
Go
11
star
31

go-reconcile

Super tiny go package which does reconcile planning
Go
11
star
32

vagrant-secret

Enable to read external secret file for configuration
Ruby
10
star
33

wercker-step-ghr

Wercker step for tcnksm/ghr, create Github Release and uploading artifacts
Shell
10
star
34

go-irkit

The unofficial golang client for IRKit
Go
9
star
35

vagrant-pushover

Add pushover notification to your vagrant
Ruby
9
star
36

docc

docc open your project document (GitHub page or README)
Go
9
star
37

dockerfile-centos-buildpack-deps

Docker CentOS Image for buildpack-deps
9
star
38

yo

Yo to your twitter friend from CLI
Go
8
star
39

misc

The collection of programs which is not general consumption
Go
8
star
40

heroku-docker-registry

Run Docker Registry on Heroku
Shell
8
star
41

rspec-logstash-filter

RSpec logstash filter on docker container
Shell
7
star
42

bash-init

The easy way to start building bash command-line application.
Go
7
star
43

docker-meetup-4-demo

Demo for docker meetup #4
Shell
7
star
44

vagrant-runc

Play with runC on Ubuntu14.04 by Vagrant
7
star
45

dockerfile-single-kafka

Dockerfile for single node kafka
Shell
7
star
46

wercker-box-gox

Wercker box for mitchellh/gox, cross-compiling golang project parallelly
6
star
47

go-httptraceutils

Small Go helper package for logging out each hook info of httptrace
Go
6
star
48

wercker-step-goveralls

Wercker step for mattn/goveralls, integrate with coveralls.io
Shell
5
star
49

go-context101

Sample codes to understand why context package
Go
5
star
50

go-distribution-scripts

Shellscripts for cross-compiling, packaging and uploading golang tool
Shell
5
star
51

hubot-google-trend

Hubot script to show recent trend words on Google
CoffeeScript
5
star
52

wercker-step-zip

Wercker step for packaging directories
Shell
4
star
53

dockerfiles

@tcnksm does Dockerfile
4
star
54

vagrant-appc

Play with CoreOS/Rocket in Vagrant
4
star
55

hubot-cron-json

Manage hubot cron job defined by json configuration file
CoffeeScript
4
star
56

wercker-step-gox

Wercker step for mitchellh/gox, cross-compiling golang project parallelly
Shell
4
star
57

oh-my-zsh-beer-theme

oh-my-zsh ๐Ÿบ theme
3
star
58

tf-dnsimple-gh-pages

Setup custom apex domain for your GitHub pages with Terraform
HCL
3
star
59

coreos-meetup-tokyo

CoreOS meetup tokyo
3
star
60

init

Initial template
Go
2
star
61

random_japanese_string

Generate random japanese strings
Ruby
2
star
62

retrobot

tweet what @tcnksm tweet 1 year ago
Ruby
2
star
63

dockerfile-go-release

Dockerfile for cross-compiling & uploading artifacts to Github Release page. Compiling and uploading are executed parallelly.
Shell
2
star
64

dist-ghr

Redirect distribution for
Go
2
star
65

go-playground

My Go Playground
Go
1
star
66

tcnksm.github.io

HTML
1
star
67

homebrew-ghr

A Homebrew formula for tcnksm/ghr
Ruby
1
star
68

tcnksm

README for @tcnksm
Go
1
star
69

ghr-demo

GHR demo
Go
1
star
70

go-cf-manifest

Go package for handling CloudFoundry manifest.yml
Go
1
star
71

dockerfile-download-deb

Dockerfile for donwloading deb package
1
star
72

scripts

Automation scripts for my daily job/life
Shell
1
star
73

writing.deeeet.com

My blog powered by octopress
Ruby
1
star