func ServerError() *Mux {
	return Match(func(ctx *c.Context) bool {
		return ctx.GetString("$phase") == "response" && ctx.Response.StatusCode >= 500
	})
}
ServerError returns a new multiplexer who matches response errors by the server.
package mux
import (
	c "gopkg.in/h2non/gentleman.v2/context"
	types "gopkg.in/h2non/gentleman.v2/plugins/bodytype"
	"regexp"
	"strings"
)
type Matcher func(ctx *c.Context) bool
func Match(matchers ...Matcher) *Mux {
	mx := New()
	mx.AddMatcher(matchers...)
	return mx
}
func Method(methods ...string) *Mux {
	return Match(func(ctx *c.Context) bool {
		if ctx.GetString("$phase") != "request" {
			return false
		}
		for _, method := range methods {
			if ctx.Request.Method == method {
				return true
			}
		}
		return false
	})
}
func Path(pattern string) *Mux {
	return Match(func(ctx *c.Context) bool {
		if ctx.GetString("$phase") != "request" {
			return false
		}
		matched, _ := regexp.MatchString(pattern, ctx.Request.URL.Path)
		return matched
	})
}
func URL(pattern string) *Mux {
	return Match(func(ctx *c.Context) bool {
		if ctx.GetString("$phase") != "request" {
			return false
		}
		matched, _ := regexp.MatchString(pattern, ctx.Request.URL.String())
		return matched
	})
}
func Host(pattern string) *Mux {
	return Match(func(ctx *c.Context) bool {
		if ctx.GetString("$phase") != "request" {
			return false
		}
		matched, _ := regexp.MatchString(pattern, ctx.Request.URL.Host)
		return matched
	})
}
func Query(key, pattern string) *Mux {
	return Match(func(ctx *c.Context) bool {
		if ctx.GetString("$phase") != "request" {
			return false
		}
		matched, _ := regexp.MatchString(pattern, ctx.Request.URL.Query().Get(key))
		return matched
	})
}
func RequestHeader(key, pattern string) *Mux {
	return Match(func(ctx *c.Context) bool {
		if ctx.GetString("$phase") != "request" {
			return false
		}
		matched, _ := regexp.MatchString(pattern, ctx.Request.Header.Get(key))
		return matched
	})
}
func ResponseHeader(key, pattern string) *Mux {
	return Match(func(ctx *c.Context) bool {
		if ctx.GetString("$phase") != "response" {
			return false
		}
		matched, _ := regexp.MatchString(pattern, ctx.Response.Header.Get(key))
		return matched
	})
}
func Type(kind string) *Mux {
	return Match(func(ctx *c.Context) bool {
		if ctx.GetString("$phase") != "response" {
			return false
		}
		if value, ok := types.Types[kind]; ok {
			kind = value
		}
		return strings.Contains(ctx.Response.Header.Get("Content-Type"), kind)
	})
}
func Status(codes ...int) *Mux {
	return Match(func(ctx *c.Context) bool {
		if ctx.GetString("$phase") != "response" {
			return false
		}
		for _, code := range codes {
			if ctx.Response.StatusCode == code {
				return true
			}
		}
		return false
	})
}
func StatusRange(start, end int) *Mux {
	return Match(func(ctx *c.Context) bool {
		return ctx.GetString("$phase") == "response" && ctx.Response.StatusCode >= start && ctx.Response.StatusCode <= end
	})
}
func Error() *Mux {
	return Match(func(ctx *c.Context) bool {
		return (ctx.GetString("$phase") == "error" && ctx.Error != nil) ||
			(ctx.GetString("$phase") == "response" && ctx.Response.StatusCode >= 500)
	})
}