4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-09-06 10:14:10 +00:00

Update vendor

This commit is contained in:
Wim
2017-06-06 00:01:05 +02:00
parent 2eecaccd1c
commit 3a183cb218
49 changed files with 534 additions and 1421 deletions

View File

@@ -31,6 +31,9 @@ type (
// IsTLS returns true if HTTP connection is TLS otherwise false.
IsTLS() bool
// IsWebSocket returns true if HTTP connection is WebSocket otherwise false.
IsWebSocket() bool
// Scheme returns the HTTP protocol scheme, `http` or `https`.
Scheme() string
@@ -219,19 +222,36 @@ func (c *context) IsTLS() bool {
return c.request.TLS != nil
}
func (c *context) IsWebSocket() bool {
upgrade := c.request.Header.Get(HeaderUpgrade)
return upgrade == "websocket" || upgrade == "Websocket"
}
func (c *context) Scheme() string {
// Can't use `r.Request.URL.Scheme`
// See: https://groups.google.com/forum/#!topic/golang-nuts/pMUkBlQBDF0
if c.IsTLS() {
return "https"
}
if scheme := c.request.Header.Get(HeaderXForwardedProto); scheme != "" {
return scheme
}
if scheme := c.request.Header.Get(HeaderXForwardedProtocol); scheme != "" {
return scheme
}
if ssl := c.request.Header.Get(HeaderXForwardedSsl); ssl == "on" {
return "https"
}
if scheme := c.request.Header.Get(HeaderXUrlScheme); scheme != "" {
return scheme
}
return "http"
}
func (c *context) RealIP() string {
ra := c.request.RemoteAddr
if ip := c.request.Header.Get(HeaderXForwardedFor); ip != "" {
ra = ip
ra = strings.Split(ip, ", ")[0]
} else if ip := c.request.Header.Get(HeaderXRealIP); ip != "" {
ra = ip
} else {
@@ -275,7 +295,7 @@ func (c *context) SetParamNames(names ...string) {
}
func (c *context) ParamValues() []string {
return c.pvalues
return c.pvalues[:len(c.pnames)]
}
func (c *context) SetParamValues(values ...string) {
@@ -385,7 +405,8 @@ func (c *context) String(code int, s string) (err error) {
}
func (c *context) JSON(code int, i interface{}) (err error) {
if c.echo.Debug {
_, pretty := c.QueryParams()["pretty"]
if c.echo.Debug || pretty {
return c.JSONPretty(code, i, " ")
}
b, err := json.Marshal(i)
@@ -429,7 +450,8 @@ func (c *context) JSONPBlob(code int, callback string, b []byte) (err error) {
}
func (c *context) XML(code int, i interface{}) (err error) {
if c.echo.Debug {
_, pretty := c.QueryParams()["pretty"]
if c.echo.Debug || pretty {
return c.XMLPretty(code, i, " ")
}
b, err := xml.Marshal(i)
@@ -471,7 +493,12 @@ func (c *context) Stream(code int, contentType string, r io.Reader) (err error)
return
}
func (c *context) File(file string) error {
func (c *context) File(file string) (err error) {
file, err = url.QueryUnescape(file) // Issue #839
if err != nil {
return
}
f, err := os.Open(file)
if err != nil {
return ErrNotFound
@@ -487,11 +514,11 @@ func (c *context) File(file string) error {
}
defer f.Close()
if fi, err = f.Stat(); err != nil {
return err
return
}
}
http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), f)
return nil
return
}
func (c *context) Attachment(file, name string) (err error) {
@@ -514,7 +541,7 @@ func (c *context) NoContent(code int) error {
}
func (c *context) Redirect(code int, url string) error {
if code < http.StatusMultipleChoices || code > http.StatusTemporaryRedirect {
if code < 300 || code > 308 {
return ErrInvalidRedirectCode
}
c.response.Header().Set(HeaderLocation, url)
@@ -548,4 +575,8 @@ func (c *context) Reset(r *http.Request, w http.ResponseWriter) {
c.query = nil
c.handler = NotFoundHandler
c.store = nil
c.path = ""
c.pnames = nil
// NOTE: Don't reset because it has to have length c.echo.maxParam at all times
// c.pvalues = nil
}