// SimpleMuxer provides the handoler for a providing a pure piping behaviour where data is left untouched as it comes in and goes out
506912
func SimpleMuxer(fx func(Reactor, interface{})) SignalMuxHandler {
	return func(r Reactor, err error, data interface{}) {
		if err != nil {
			r.ReplyError(err)
			return
		}

		fx(r, data)
	}
}
1287086
func (pc *PyramidChunker) cleanChunkLevels() {
	for i, l := range pc.chunkLevel {
		if l == nil {
			pc.chunkLevel = append(pc.chunkLevel[:i], append(pc.chunkLevel[i+1:], nil)...)
		}
	}
}
360641
func (msm *MultistreamMuxer) AddHandler(protocol string, handler HandlerFunc) {
	msm.AddHandlerWithFunc(protocol, fulltextMatch(protocol), handler)
}
683245
func IdentityMuxer() Handler {
	return func(r Publisher, err error, data interface{}) {
		if err != nil {
			r.ReplyError(err)
			return
		}
		r.Reply(data)
	}
}
1111508
func NewServeMux() *ServeMux {
	mux := &ServeMux{
		router: &Router{},
	}
	mux.router.mux = mux
	return mux
}
255566
func (l *Logger) Simple() *SimpleTask {
	t := NewSimpleTask()
	l.Enqueue(t)

	return t
}
24672
func (m *PathRecorderMux) refreshMuxLocked() {
	newMux := &pathHandler{
		muxName:         m.name,
		pathToHandler:   map[string]http.Handler{},
		prefixHandlers:  []prefixHandler{},
		notFoundHandler: http.NotFoundHandler(),
	}
	if m.notFoundHandler != nil {
		newMux.notFoundHandler = m.notFoundHandler
	}
	for path, handler := range m.pathToHandler {
		newMux.pathToHandler[path] = handler
	}

	keys := sets.StringKeySet(m.prefixToHandler).List()
	sort.Sort(sort.Reverse(byPrefixPriority(keys)))
	for _, prefix := range keys {
		newMux.prefixHandlers = append(newMux.prefixHandlers, prefixHandler{
			prefix:  prefix,
			handler: m.prefixToHandler[prefix],
		})
	}

	m.mux.Store(newMux)
}
400671
func (m *Medeina) OnMux(path string, handle http.Handler) {
	var path_slash string
	if path[0] != '/' {
		path_slash = "/" + path
	} else {
		path_slash = path
	}
	m.OnHandler(path, HandlerPathPrefix(path_slash, handle))
}
1240364
func IdentityValueMuxer(v interface{}) Handler {
	return func(r Publisher, err error, _ interface{}) {
		if err != nil {
			r.ReplyError(err)
			return
		}
		r.Reply(v)
	}
}
901951
func ServeMux(mux *http.ServeMux, address, port, cert, key string) error {
	listen := fmt.Sprintf("%s:%s", address, port)
	if cert == "false" || key == "false" {
		fmt.Printf("About to listen on http://%s/\n", listen)
		err := http.ListenAndServe(listen, mux)
		if err != nil {
			return err
		}
	} else {
		fmt.Printf("About to listen on https://%s/\n", listen)
		err := http.ListenAndServeTLS(listen, cert, key, mux)
		if err != nil {
			return err
		}
	}
	return nil
}
492179
func muxOutput(streamLabel string, lines chan []byte, clients <-chan net.Conn, targets <-chan io.WriteCloser) {
	var logs []io.WriteCloser
	var conns []io.WriteCloser

	writeAndFilter := func(wc io.WriteCloser, line []byte) bool {
		_, err := wc.Write(line)
		if err != nil {
			wc.Close()
		}
		return err != nil
	}

	logsWriteAndFilter := func(wc io.WriteCloser, line []byte) bool {
		out := []byte(fmt.Sprintf("%s %s %s", time.Now().Format(time.RFC3339Nano), streamLabel, line))
		return writeAndFilter(wc, out)
	}

	for {
		select {
		// an incoming output line to multiplex
		// TODO(lucab): ordered non-blocking writes
		case l := <-lines:
			conns = filterTargets(conns, l, writeAndFilter)
			logs = filterTargets(logs, l, logsWriteAndFilter)

		// a new remote client
		case c := <-clients:
			conns = append(conns, c)

		// a new local log target
		case t := <-targets:
			logs = append(logs, t)
		}
	}
}
221047
func BufferedPipe(n int) (Receiver, Sender) {
	c := make(chan interface{}, n)
	return pReceiver(c), pSender(c)
}
201486
func (mux *ServeMux) HandleFunc(pattern string,
	f func(l *net.UDPConn, a *net.UDPAddr, m *Message) *Message) {
	mux.Handle(pattern, FuncHandler(f))
}
1325191
func NewMux() *Mux {
	return &Mux{
		mux: http.NewServeMux(),
		log: func(err error) { println(err.Error()) },
	}
}
185983
func GetMux() *mux.Router {

	r := mux.NewRouter()
	r.HandleFunc(`/`, HomeHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/ip`, IPHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/user-agent`, UserAgentHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/headers`, HeadersHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/get`, GetHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/post`, PostHandler).Methods(http.MethodPost)
	r.HandleFunc(`/redirect/{n:[\d]+}`, RedirectHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/absolute-redirect/{n:[\d]+}`, AbsoluteRedirectHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/redirect-to`, RedirectToHandler).Methods(http.MethodGet, http.MethodHead).Queries("url", "{url:.+}")
	r.HandleFunc(`/status/{code:[\d]+}`, StatusHandler)
	r.HandleFunc(`/bytes/{n:[\d]+}`, BytesHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/delay/{n:\d+(?:\.\d+)?}`, DelayHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/stream/{n:[\d]+}`, StreamHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/drip`, DripHandler).Methods(http.MethodGet, http.MethodHead).Queries(
		"numbytes", `{numbytes:\d+}`,
		"duration", `{duration:\d+(?:\.\d+)?}`)
	r.HandleFunc(`/cookies`, CookiesHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/cookies/set`, SetCookiesHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/cookies/delete`, DeleteCookiesHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/cache`, CacheHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/cache/{n:[\d]+}`, SetCacheHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/gzip`, GZIPHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/deflate`, DeflateHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/html`, HTMLHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/xml`, XMLHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/robots.txt`, RobotsTXTHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/deny`, DenyHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/basic-auth/{u}/{p}`, BasicAuthHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/hidden-basic-auth/{u}/{p}`, HiddenBasicAuthHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/image/gif`, GIFHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/image/png`, PNGHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/image/jpeg`, JPEGHandler).Methods(http.MethodGet, http.MethodHead)
	return r
}
1109162
func (l *BytesBufferLogger) Flush() {
	l.mux.Lock()
	defer l.mux.Unlock()
	l.buf.Reset()
}
960107
func (msm *MultistreamMuxer) RemoveHandler(protocol string) {
	msm.handlerlock.Lock()
	defer msm.handlerlock.Unlock()

	msm.removeHandler(protocol)
}