<commit_before>package server

import (
	"github.com/vulcand/oxy/forward"
	"github.com/vulcand/oxy/roundrobin"
	"github.com/vulcand/oxy/stream"
	"github.com/vulcand/oxy/cbreaker"
	"net/http"
	"net/url"
)

type ReverseProxy struct {
	stream *stream.Streamer
}

func NewReverseProxy(backends []string) *ReverseProxy {
	fwd, _ := forward.New()
	cb, _ := cbreaker.New(fwd, `NetworkErrorRatio() > 0.5`)
	lb, _ := roundrobin.New(cb)
	for _, backend := range backends {
		target, _ := url.Parse(backend)
		lb.UpsertServer(target)
	}
	stream, _ := stream.New(lb, stream.Retry(`(IsNetworkError() || ResponseCode() >= 500) && Attempts() < 2`))
	return &ReverseProxy{stream: stream}
}

func (rp *ReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	rp.stream.ServeHTTP(w, r)
}<commit_msg>Rename stream to buffer (oxy stream lib update) + move circuit breaker in the middleware chain<commit_after>package server

import (
	"github.com/vulcand/oxy/forward"
	"github.com/vulcand/oxy/roundrobin"
	"github.com/vulcand/oxy/buffer"
	"github.com/vulcand/oxy/cbreaker"
	"net/http"
	"net/url"
)

type ReverseProxy struct {
	handler http.Handler
}

func NewReverseProxy(backends []string) *ReverseProxy {
	fwd, _ := forward.New()
	lb, _ := roundrobin.New(fwd)
	for _, backend := range backends {
		target, _ := url.Parse(backend)
		lb.UpsertServer(target)
	}
	buff, _ := buffer.New(lb, buffer.Retry(`(IsNetworkError() || ResponseCode() >= 500) && Attempts() < 2`))
	cb, _ := cbreaker.New(buff, `NetworkErrorRatio() > 0.5`)
	return &ReverseProxy{handler: cb}
}

func (rp *ReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	rp.handler.ServeHTTP(w, r)
}
{'fraction_non_alphanumeric': 0.16043425814234016, 'fraction_numerical': 0.007237635705669481, 'mean_word_length': 4.925, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2324176', 'n_tokens_mistral': 667, 'n_tokens_neox': 637, 'n_words': 118}