func (s *Server) RouteToHandler(method string, path interface{}, handler http.HandlerFunc) {
	s.rwMutex.Lock()
	defer s.rwMutex.Unlock()
	rh := routedHandler{
		method:  method,
		handler: handler,
	}
	switch p := path.(type) {
	case *regexp.Regexp:
		rh.pathRegexp = p
	case string:
		rh.path = p
	default:
		panic("path must be a string or a regular expression")
	}
	for i, existingRH := range s.routedHandlers {
		if existingRH.method == method &&
			reflect.DeepEqual(existingRH.pathRegexp, rh.pathRegexp) &&
			existingRH.path == rh.path {
			s.routedHandlers[i] = rh
			return
		}
	}
	s.routedHandlers = append(s.routedHandlers, rh)
}
RouteToHandler can be used to register handlers that will always handle requests that match
the passed in method and path.

The path may be either a string object or a *regexp.Regexp.
package ghttp
import (
	"fmt"
	"io"
	"net/http"
	"net/http/httptest"
	"net/http/httputil"
	"reflect"
	"regexp"
	"strings"
	"sync"
	. "github.com/onsi/gomega"
)
func new() *Server {
	return &Server{
		AllowUnhandledRequests:     false,
		UnhandledRequestStatusCode: http.StatusInternalServerError,
		rwMutex:                    &sync.RWMutex{},
	}
}
type routedHandler struct {
	method     string
	pathRegexp *regexp.Regexp
	path       string
	handler    http.HandlerFunc
}
func NewServer() *Server {
	s := new()
	s.HTTPTestServer = httptest.NewServer(s)
	return s
}
func NewUnstartedServer() *Server {
	s := new()
	s.HTTPTestServer = httptest.NewUnstartedServer(s)
	return s
}
func NewTLSServer() *Server {
	s := new()
	s.HTTPTestServer = httptest.NewTLSServer(s)
	return s
}
type Server struct {
	HTTPTestServer *httptest.Server
	AllowUnhandledRequests bool
	UnhandledRequestStatusCode int
	Writer io.Writer
	receivedRequests []*http.Request
	requestHandlers  []http.HandlerFunc
	routedHandlers   []routedHandler
	rwMutex *sync.RWMutex
	calls   int
}
func (s *Server) Start() {
	s.HTTPTestServer.Start()
}
func (s *Server) URL() string {
	s.rwMutex.RLock()
	defer s.rwMutex.RUnlock()
	return s.HTTPTestServer.URL
}
func (s *Server) Addr() string {
	s.rwMutex.RLock()
	defer s.rwMutex.RUnlock()
	return s.HTTPTestServer.Listener.Addr().String()
}
func (s *Server) Close() {
	s.rwMutex.Lock()
	server := s.HTTPTestServer
	s.HTTPTestServer = nil
	s.rwMutex.Unlock()
	if server != nil {
		server.Close()
	}
}
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	s.rwMutex.Lock()
	defer func() {
		e := recover()
		if e != nil {
			w.WriteHeader(http.StatusInternalServerError)
		}
		eAsString, ok := e.(string)
		if ok && strings.Contains(eAsString, "defer GinkgoRecover()") {
			return
		}
		defer func() {
			recover()
		}()
		Expect(e).Should(BeNil(), "Handler Panicked")
	}()
	if s.Writer != nil {
		s.Writer.Write([]byte(fmt.Sprintf("GHTTP Received Request: %s - %s\n", req.Method, req.URL)))
	}
	s.receivedRequests = append(s.receivedRequests, req)
	if routedHandler, ok := s.handlerForRoute(req.Method, req.URL.Path); ok {
		s.rwMutex.Unlock()
		routedHandler(w, req)
	} else if s.calls < len(s.requestHandlers) {
		h := s.requestHandlers[s.calls]
		s.calls++
		s.rwMutex.Unlock()
		h(w, req)
	} else {
		s.rwMutex.Unlock()
		if s.GetAllowUnhandledRequests() {
			io.ReadAll(req.Body)
			req.Body.Close()
			w.WriteHeader(s.GetUnhandledRequestStatusCode())
		} else {
			formatted, err := httputil.DumpRequest(req, true)
			Expect(err).NotTo(HaveOccurred(), "Encountered error while dumping HTTP request")
			Expect(string(formatted)).Should(BeNil(), "Received Unhandled Request")
		}
	}
}
func (s *Server) ReceivedRequests() []*http.Request {
	s.rwMutex.RLock()
	defer s.rwMutex.RUnlock()
	return s.receivedRequests
}