mirror of
https://github.com/labstack/echo.git
synced 2025-01-12 01:22:21 +02:00
parent
049518f8c4
commit
b218599906
2
bind.go
2
bind.go
@ -51,7 +51,7 @@ func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
|
|||||||
return NewHTTPError(http.StatusBadRequest, err.Error())
|
return NewHTTPError(http.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case strings.HasPrefix(ctype, MIMEApplicationXML):
|
case strings.HasPrefix(ctype, MIMEApplicationXML), strings.HasPrefix(ctype, MIMETextXML):
|
||||||
if err = xml.NewDecoder(req.Body).Decode(i); err != nil {
|
if err = xml.NewDecoder(req.Body).Decode(i); err != nil {
|
||||||
if ute, ok := err.(*xml.UnsupportedTypeError); ok {
|
if ute, ok := err.(*xml.UnsupportedTypeError); ok {
|
||||||
return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unsupported type error: type=%v, error=%v", ute.Type, ute.Error()))
|
return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unsupported type error: type=%v, error=%v", ute.Type, ute.Error()))
|
||||||
|
@ -96,6 +96,8 @@ func TestBindJSON(t *testing.T) {
|
|||||||
func TestBindXML(t *testing.T) {
|
func TestBindXML(t *testing.T) {
|
||||||
testBindOkay(t, strings.NewReader(userXML), MIMEApplicationXML)
|
testBindOkay(t, strings.NewReader(userXML), MIMEApplicationXML)
|
||||||
testBindError(t, strings.NewReader(invalidContent), MIMEApplicationXML)
|
testBindError(t, strings.NewReader(invalidContent), MIMEApplicationXML)
|
||||||
|
testBindOkay(t, strings.NewReader(userXML), MIMETextXML)
|
||||||
|
testBindError(t, strings.NewReader(invalidContent), MIMETextXML)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBindForm(t *testing.T) {
|
func TestBindForm(t *testing.T) {
|
||||||
@ -292,7 +294,7 @@ func testBindError(t *testing.T, r io.Reader, ctype string) {
|
|||||||
err := c.Bind(u)
|
err := c.Bind(u)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(ctype, MIMEApplicationJSON), strings.HasPrefix(ctype, MIMEApplicationXML),
|
case strings.HasPrefix(ctype, MIMEApplicationJSON), strings.HasPrefix(ctype, MIMEApplicationXML), strings.HasPrefix(ctype, MIMETextXML),
|
||||||
strings.HasPrefix(ctype, MIMEApplicationForm), strings.HasPrefix(ctype, MIMEMultipartForm):
|
strings.HasPrefix(ctype, MIMEApplicationForm), strings.HasPrefix(ctype, MIMEMultipartForm):
|
||||||
if assert.IsType(t, new(HTTPError), err) {
|
if assert.IsType(t, new(HTTPError), err) {
|
||||||
assert.Equal(t, http.StatusBadRequest, err.(*HTTPError).Code)
|
assert.Equal(t, http.StatusBadRequest, err.(*HTTPError).Code)
|
||||||
|
2
echo.go
2
echo.go
@ -145,6 +145,8 @@ const (
|
|||||||
MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8
|
MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8
|
||||||
MIMEApplicationXML = "application/xml"
|
MIMEApplicationXML = "application/xml"
|
||||||
MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8
|
MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8
|
||||||
|
MIMETextXML = "text/xml"
|
||||||
|
MIMETextXMLCharsetUTF8 = MIMETextXML + "; " + charsetUTF8
|
||||||
MIMEApplicationForm = "application/x-www-form-urlencoded"
|
MIMEApplicationForm = "application/x-www-form-urlencoded"
|
||||||
MIMEApplicationProtobuf = "application/protobuf"
|
MIMEApplicationProtobuf = "application/protobuf"
|
||||||
MIMEApplicationMsgpack = "application/msgpack"
|
MIMEApplicationMsgpack = "application/msgpack"
|
||||||
|
Loading…
Reference in New Issue
Block a user