1
0
mirror of https://github.com/labstack/echo.git synced 2025-12-21 23:57:40 +02:00

Refactored media types and headers

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2015-05-10 22:34:31 -07:00
parent 3b87f90bfd
commit 8ace8e2143
3 changed files with 31 additions and 22 deletions

33
echo.go
View File

@@ -73,16 +73,25 @@ const (
// TRACE HTTP method
TRACE = "TRACE"
MIMEJSON = "application/json"
MIMEText = "text/plain"
MIMEHTML = "text/html"
MIMEForm = "application/x-www-form-urlencoded"
MIMEMultipartForm = "multipart/form-data"
//-------------
// Media types
//-------------
HeaderAccept = "Accept"
HeaderContentDisposition = "Content-Disposition"
HeaderContentLength = "Content-Length"
HeaderContentType = "Content-Type"
ApplicationJSON = "application/json"
ApplicationProtobuf = "application/protobuf"
TextPlain = "text/plain"
TextHTML = "text/html"
ApplicationForm = "application/x-www-form-urlencoded"
MultipartForm = "multipart/form-data"
//---------
// Headers
//---------
Accept = "Accept"
ContentDisposition = "Content-Disposition"
ContentLength = "Content-Length"
ContentType = "Content-Type"
)
var (
@@ -138,11 +147,11 @@ func New() (e *Echo) {
http.Error(c.Response, he.Message, he.Code)
})
e.Binder(func(r *http.Request, v interface{}) *HTTPError {
ct := r.Header.Get(HeaderContentType)
ct := r.Header.Get(ContentType)
err := UnsupportedMediaType
if strings.HasPrefix(ct, MIMEJSON) {
if strings.HasPrefix(ct, ApplicationJSON) {
err = json.NewDecoder(r.Body).Decode(v)
} else if strings.HasPrefix(ct, MIMEForm) {
} else if strings.HasPrefix(ct, ApplicationForm) {
err = nil
}
if err != nil {