containous/oxy

Name: oxy

Owner: Containous

Description: Go middlewares for HTTP servers & proxies

Forked from: vulcand/oxy

Created: 2016-03-07 22:19:10.0

Updated: 2018-01-19 15:34:58.0

Pushed: 2018-01-18 14:25:05.0

Homepage:

Size: 372

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Oxy

Oxy is a Go library with HTTP handlers that enhance HTTP standard library:

It is designed to be fully compatible with http standard library, easy to customize and reuse.

Status
Quickstart

Every handler is http.Handler, so writing and plugging in a middleware is easy. Let us write a simple reverse proxy as an example:

Simple reverse proxy

rt (
et/http"
ithub.com/vulcand/oxy/forward"
ithub.com/vulcand/oxy/testutils"


orwards incoming requests to whatever location URL points to, adds proper forwarding headers
 _ := forward.New()

rect := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
// let us forward this request to another server
    req.URL = testutils.ParseURI("http://localhost:63450")
    fwd.ServeHTTP(w, req)


hat's it! our reverse proxy is ready!
 &http.Server{
Addr:           ":8080",
Handler:        redirect,

stenAndServe()

As a next step, let us add a round robin load-balancer:

rt (
et/http"
ithub.com/vulcand/oxy/forward"
ithub.com/vulcand/oxy/roundrobin"


orwards incoming requests to whatever location URL points to, adds proper forwarding headers
 _ := forward.New()
_ := roundrobin.New(fwd)

psertServer(url1)
psertServer(url2)

 &http.Server{
Addr:           ":8080",
Handler:        lb,

stenAndServe()

What if we want to handle retries and replay the request in case of errors? stream handler will help:

rt (
et/http"
ithub.com/vulcand/oxy/forward"
ithub.com/vulcand/oxy/roundrobin"


orwards incoming requests to whatever location URL points to, adds proper forwarding headers

 _ := forward.New()
_ := roundrobin.New(fwd)

tream will read the request body and will replay the request again in case if forward returned status
orresponding to nework error (e.g. Gateway Timeout)
am, _ := stream.New(lb, stream.Retry(`IsNetworkError() && Attempts() < 2`))

psertServer(url1)
psertServer(url2)

hat's it! our reverse proxy is ready!
 &http.Server{
Addr:           ":8080",
Handler:        stream,

stenAndServe()

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.