mirror of
https://github.com/labstack/echo.git
synced 2025-02-03 13:11:39 +02:00
Last-Modified header for static content
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
a7697fe480
commit
5b5df5bf44
@ -295,8 +295,8 @@ func (c *context) Attachment(file string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, name := filepath.Split(file)
|
_, name := filepath.Split(file)
|
||||||
c.response.Header().Set(ContentDisposition, "attachment; filename="+name)
|
|
||||||
c.response.Header().Set(ContentType, detectContentType(file))
|
c.response.Header().Set(ContentType, detectContentType(file))
|
||||||
|
c.response.Header().Set(ContentDisposition, "attachment; filename="+name)
|
||||||
c.response.WriteHeader(http.StatusOK)
|
c.response.WriteHeader(http.StatusOK)
|
||||||
_, err = io.Copy(c.response, f)
|
_, err = io.Copy(c.response, f)
|
||||||
return
|
return
|
||||||
@ -339,8 +339,8 @@ func (c *context) Object() *context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ServeContent(req engine.Request, res engine.Response, f http.File, fi os.FileInfo) error {
|
func ServeContent(req engine.Request, res engine.Response, f http.File, fi os.FileInfo) error {
|
||||||
// TODO: http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), f)
|
|
||||||
res.Header().Set(ContentType, detectContentType(fi.Name()))
|
res.Header().Set(ContentType, detectContentType(fi.Name()))
|
||||||
|
res.Header().Set(LastModified, fi.ModTime().UTC().Format(http.TimeFormat))
|
||||||
res.WriteHeader(http.StatusOK)
|
res.WriteHeader(http.StatusOK)
|
||||||
_, err := io.Copy(res, f)
|
_, err := io.Copy(res, f)
|
||||||
return err
|
return err
|
||||||
|
7
echo.go
7
echo.go
@ -136,6 +136,7 @@ const (
|
|||||||
ContentEncoding = "Content-Encoding"
|
ContentEncoding = "Content-Encoding"
|
||||||
ContentLength = "Content-Length"
|
ContentLength = "Content-Length"
|
||||||
ContentType = "Content-Type"
|
ContentType = "Content-Type"
|
||||||
|
LastModified = "Last-Modified"
|
||||||
Location = "Location"
|
Location = "Location"
|
||||||
Upgrade = "Upgrade"
|
Upgrade = "Upgrade"
|
||||||
Vary = "Vary"
|
Vary = "Vary"
|
||||||
@ -163,6 +164,8 @@ var (
|
|||||||
|
|
||||||
ErrUnsupportedMediaType = NewHTTPError(http.StatusUnsupportedMediaType)
|
ErrUnsupportedMediaType = NewHTTPError(http.StatusUnsupportedMediaType)
|
||||||
ErrNotFound = NewHTTPError(http.StatusNotFound)
|
ErrNotFound = NewHTTPError(http.StatusNotFound)
|
||||||
|
ErrUnauthorized = NewHTTPError(http.StatusUnauthorized)
|
||||||
|
ErrMethodNotAllowed = NewHTTPError(http.StatusMethodNotAllowed)
|
||||||
ErrRendererNotRegistered = errors.New("renderer not registered")
|
ErrRendererNotRegistered = errors.New("renderer not registered")
|
||||||
ErrInvalidRedirectCode = errors.New("invalid redirect status code")
|
ErrInvalidRedirectCode = errors.New("invalid redirect status code")
|
||||||
|
|
||||||
@ -171,11 +174,11 @@ var (
|
|||||||
//----------------
|
//----------------
|
||||||
|
|
||||||
notFoundHandler = HandlerFunc(func(c Context) error {
|
notFoundHandler = HandlerFunc(func(c Context) error {
|
||||||
return NewHTTPError(http.StatusNotFound)
|
return ErrNotFound
|
||||||
})
|
})
|
||||||
|
|
||||||
methodNotAllowedHandler = HandlerFunc(func(c Context) error {
|
methodNotAllowedHandler = HandlerFunc(func(c Context) error {
|
||||||
return NewHTTPError(http.StatusMethodNotAllowed)
|
return ErrMethodNotAllowed
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package middleware
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/labstack/echo"
|
"github.com/labstack/echo"
|
||||||
)
|
)
|
||||||
@ -43,7 +42,7 @@ func BasicAuth(fn BasicAuthFunc, options ...BasicAuthOptions) echo.MiddlewareFun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.Response().Header().Set(echo.WWWAuthenticate, basic+" realm=Restricted")
|
c.Response().Header().Set(echo.WWWAuthenticate, basic+" realm=Restricted")
|
||||||
return echo.NewHTTPError(http.StatusUnauthorized)
|
return echo.ErrUnauthorized
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user