func (as *AcceptorServer) handlePrepare(w http.ResponseWriter, r *http.Request) {
	var (
		key, _ = url.PathUnescape(mux.Vars(r)["key"])
		age    = getAge(r.Header)
		b      = getBallot(r.Header)
	)
	state, ballot, err := as.acceptor.Prepare(r.Context(), key, age, b)
	setBallot(w.Header(), ballot)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.Write(state)
}
Prepare(ctx context.Context, key string, age Age, b Ballot) (value []byte, current Ballot, err error)
package httpapi
import (
	"bytes"
	"context"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"regexp"
	"strings"
	"time"
	"github.com/gorilla/mux"
	"github.com/pkg/errors"
	"github.com/peterbourgon/caspaxos/extension"
	"github.com/peterbourgon/caspaxos/internal/eventsource"
	"github.com/peterbourgon/caspaxos/protocol"
)
type AcceptorServer struct {
	acceptor protocol.Acceptor
	*mux.Router
}
var _ http.Handler = (*AcceptorServer)(nil)
const (
	ageHeaderKey      = "X-Caspaxos-Age"
	ageHeaderRegex    = "^([0-9]+):(.*)$"
	ballotHeaderKey   = "X-Caspaxos-Ballot"
	ballotHeaderRegex = "^([0-9]+)/(.*)$"
	versionHeaderKey  = "X-Caspaxos-Ext-Version"
)
var (
	ageRe    = regexp.MustCompile(ageHeaderRegex)
	ballotRe = regexp.MustCompile(ballotHeaderRegex)
)
func NewAcceptorServer(acceptor protocol.Acceptor) *AcceptorServer {
	as := &AcceptorServer{
		acceptor: acceptor,
	}
	r := mux.NewRouter()
	{
		r.StrictSlash(true)
		r.Methods("POST").Path("/prepare/{key}").HeadersRegexp(ageHeaderKey, ageHeaderRegex, ballotHeaderKey, ballotHeaderRegex).HandlerFunc(as.handlePrepare)
		r.Methods("POST").Path("/accept/{key}").HeadersRegexp(ageHeaderKey, ageHeaderRegex, ballotHeaderKey, ballotHeaderRegex).HandlerFunc(as.handleAccept)
		r.Methods("POST").Path("/reject-by-age").HeadersRegexp(ageHeaderKey, ageHeaderRegex).HandlerFunc(as.handleRejectByAge)
		r.Methods("POST").Path("/remove-if-equal/{key}").HandlerFunc(as.handleRemoveIfEqual)
		r.Methods("POST").Path("/watch/{key}").HandlerFunc(as.handleWatch)
	}
	as.Router = r
	return as
}