1
0
mirror of https://github.com/labstack/echo.git synced 2025-12-19 23:52:19 +02:00
Commit Graph

55 Commits

Author SHA1 Message Date
Vishal Rana
d0137c3e80 Revert Issue #2813 fix based on maintainer feedback
Revert the DefaultBinder empty body handling changes following
@aldas's concerns about:
- Body replacement potentially interfering with custom readers
- Lack of proper reproduction case for the original issue
- Potential over-engineering for an edge case

The "read one byte and reconstruct body" approach could interfere
with users who add custom readers with specific behavior.

Waiting for better reproduction case and less invasive solution.

Refs: https://github.com/labstack/echo/issues/2813#issuecomment-3294563361

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-15 19:08:27 -07:00
Vishal Rana
2fb84197e9 Fix DefaultBinder empty body handling for unknown ContentLength
Fix issue where POST requests with empty bodies and ContentLength=-1
(unknown/chunked encoding) incorrectly fail with 415 Unsupported Media Type.

The DefaultBinder.BindBody method now properly detects truly empty bodies
when ContentLength=-1 by peeking at the first byte. If no content is found,
it returns early without error. If content exists, it reconstructs the body
to preserve the original data.

Fixes #2813

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-15 18:47:57 -07:00
cui
9acf534182 refactor to use reflect.TypeFor (#2812) 2025-08-25 22:32:58 +03:00
zhuhaicity
ce0b12ae53 chore: fix some typos in comment (#2735)
Signed-off-by: zhuhaicity <zhuhai@52it.net>
2025-01-12 09:28:38 +02:00
Masahiro Furudate
0368ed87f2 Add Conditions to Ensure Bind Succeeds with Transfer-Encoding: chunked (#2717)
* Add conditions to ensure Bind succeeds with `Transfer-Encoding: chunked`.

* Revert the ContentLength conditions for BindBody
2024-12-11 12:04:21 +02:00
pham vinh dat
c4410fe0b8 fix(bind body): content-length can be -1 2024-11-22 11:58:56 +02:00
toimtoimtoim
d5b32c6e47 Refactor work done by martinpasaribu <martin.yonathan305@gmail.com> (binding multipart files by using struct tags) 2024-10-20 21:03:50 +03:00
martinpasaribu
fb769d71b5 🎨 : add some test case for multipart file 2024-10-20 21:03:50 +03:00
martinpasaribu
d1ab8e8544 bind: add support of multipart multi files 2024-10-20 21:03:50 +03:00
Saloni Agarwal
f13e2640f0 bind: Maintain backwards compatibility for map[string]interface{} binding (#2656)
* bind: Maintain backwards compatibility for map[string]interface{} binding

* bind to single string for map[string]interface{}{}
2024-07-22 07:33:01 +03:00
Martti T
011acb4732 default binder can bind pointer to slice as struct field. For example *[]string (#2608) 2024-03-13 22:07:08 +02:00
Martti T
c57fcb3746 Default binder can use UnmarshalParams(params []string) error interface to bind multiple input values at one go. (#2607) 2024-03-11 22:49:58 +02:00
Martti T
3598f295f9 Change type definition blocks to single declarations. This helps copy/pasting Echo code in examples. (#2606) 2024-03-09 07:53:07 -08:00
Martti T
a842444e8f Add SPDX licence comments to files. See https://spdx.dev/learn/handling-license-info/ (#2604) 2024-03-09 11:21:24 +02:00
Georg Müller
ea529bbab6 binder: allow binding to a nil map 2024-02-13 20:16:18 +02:00
Martti T
60fc2fb1b7 binder: make binding to Map work better with string destinations (#2554) 2023-12-20 15:32:51 +02:00
toimtoimtoim
8e425c0431 gofmt fixes to comments 2023-05-12 22:14:29 +03:00
Clement JACOB
eb371a9e64 Adding support for HEAD method query params binding (#2027)
* Adding support for HEAD method query params binding.
* Update comment for added HEAD method for bind

Co-authored-by: Roland Lammel <roland@lammel.net>
2022-01-24 10:28:48 +01:00
Hosh
5e791b0787 Allow for custom JSON encoding implementations (#1880)
* Allow for custom JSON encoding implementations

Co-authored-by: toimtoimtoim <desinformatsioon@gmail.com>
2021-07-05 22:33:19 +03:00
Alexander Pochill
7846e3fa6b feat: Bind data using headers as source (#1866)
Currently, echo supports binding data from query, path or body.
Sometimes we need to read bind data from headers. It would be nice to
automatically bind those using the `bindData` func, which is already
well prepared to accept `http.Header`.

I didn't add this to the `Bind` func, so this will not happen
automatically. Main reason is backwards compatability. It might be
confusing if variables are bound from headers when upgrading, and might
even have become a security issue as pointed out in #1670.

* Add docs for BindHeaders
* Add test for BindHeader with invalid data type
2021-05-25 14:50:49 +02:00
lipengwei
1aef300cf4 explicitly return an error instead of hiding it 2021-05-08 22:50:31 +03:00
lipengwei
18d7fe11df Fix #1858: Add query params binding support for anonymous struct pointer filed 2021-05-08 22:50:31 +03:00
Martti T
67f6346df2 Fix Bind() when target is array/slice and path/query params complain target not being struct (#1835)
For path/query params binding we do not try (silently return) to bind when target is not struct.
Recreates PR #1574 and fixes #1565
2021-04-06 09:05:33 +02:00
Martti T
02ed3f3126 Fix #1729 Binding query/path params and form fields to struct only works for explicit tags (#1734)
* Binding query/path params and form fields to struct only works for fields that have explicit TAG defined on struct
* remove unnecessary benchmark after change because it is not valid test anymore
2021-01-05 11:04:24 +01:00
toimtoimtoim
4d626c210d c.Bind() uses query params only for GET or DELETE methods. This restores pre v.4.1.11 behavior. 2020-12-20 11:05:42 +02:00
toimtoimtoim
bd5810f5b5 separate methods to bind only query params, path params, request body 2020-12-13 11:19:05 +02:00
Eugene
399da56370 Improve bind performance (#1469)
* Improve bind performance

By some slight optimisations and lesser reflect usage now binding has significantly better performance:

name                    old time/op    new time/op    delta
BindbindData-8            21.2µs ± 2%    13.5µs ± 2%  -36.66%  (p=0.000 n=16+18)
BindbindDataWithTags-8    22.1µs ± 1%    16.4µs ± 2%  -26.03%  (p=0.000 n=20+20)

name                    old alloc/op   new alloc/op   delta
BindbindData-8            2.40kB ± 0%    1.33kB ± 0%  -44.64%  (p=0.000 n=20+20)
BindbindDataWithTags-8    2.31kB ± 0%    1.54kB ± 0%  -33.19%  (p=0.000 n=20+20)

name                    old allocs/op  new allocs/op  delta
BindbindData-8               297 ± 0%       122 ± 0%  -58.92%  (p=0.000 n=20+20)
BindbindDataWithTags-8       267 ± 0%       125 ± 0%  -53.18%  (p=0.000 n=20+20)

* Remove creation of new value in unmarshalFieldNonPtr
2020-01-08 13:40:52 -08:00
Vishal Rana
7c5e9ab0d9 Fixed #988
Signed-off-by: Vishal Rana <vr@labstack.com>
2019-10-24 14:59:52 -07:00
Bob Hall
b129098169 dont return 400 for empty bodies (#1410)
* dont return 400 for empty bodies

* remove test for missing contentlength 0
2019-09-30 10:56:32 -07:00
Vishal Rana
9bf857f14c Nil check for bind #988
Signed-off-by: Vishal Rana <vr@labstack.com>
2019-07-14 22:39:07 -07:00
Vishal Rana
da45981491 Fixed #988
Signed-off-by: Vishal Rana <vr@labstack.com>
2019-07-14 21:35:59 -07:00
Vishal Rana
8fb7b5be27 Closes #1353
Signed-off-by: Vishal Rana <vr@labstack.com>
2019-06-27 10:52:17 -07:00
kolaente
858270f6f5 Added feature to map url params to a struct with the default binder (#1165)
* Added feature to map url params to a struct with the default binder

* Added test for mix of POST data and bound params

* Renamed variables

* Added error check

* Removed unneded fix
2019-06-21 06:12:55 -07:00
Garrett D'Amore
c824b8ddc3 Add support for encoding.TextUnmarshaler in bind. (#1314) 2019-06-09 09:39:54 -07:00
Evgeniy Kulikov
282a44d4ad Remove unreachable code (#1254)
`if` <-> `else if` <-> `else` has `return` and after `else` was `return`
2019-01-28 07:59:36 -08:00
Emir Ribić
c8fd197fa8 Replace http constants with stdlib ones, i.e.: http.MethodGet instead of echo.GET (#1205) 2018-10-14 20:46:58 +05:30
Thuc Le
f7470482fe Support internal error when Bind() data #888 (#1164) 2018-09-28 10:41:13 -07:00
Emir Ribić
688ab2bec6 Remove unecessery if-s and else-s (#1189) 2018-09-07 07:58:04 -07:00
Brandon Hansen
6007218835 case sensitive matching prioritized 2018-07-03 13:04:50 -07:00
Brandon Hansen
01cfe83efe Enable case insensitive query param matching
Unmarshalling body params with json.Unmarshal supports case-insensitive
matching against struct tags.  Matching query params case insensitive
provides a more sane and consistent experience for API consumers.

The original url.Values keys remain case sensitive.
2018-07-03 13:04:50 -07:00
AnuchitO
d36ff72961 Add field name in Error message when Binding type mismatch
Old error message
`
Unmarshal type error: expected=int, got=string, offset=47
`
New error message
`
Unmarshal type error: expected=int, got=string, field=age, offset=47
`
Make it easy to fix for client.
2018-05-01 06:51:22 -07:00
Evgeniy Kulikov
f49d166e6f [FIX] Cleanup code (#1061)
Code cleanup
2018-02-21 10:44:17 -08:00
Vishal Rana
70c18060bd Fixed #988, Closed #989
Signed-off-by: Vishal Rana <vr@labstack.com>
2017-08-14 21:48:19 -07:00
Vishal Rana
2b6ea65ccd Removed duplicated code in binder
Signed-off-by: Vishal Rana <vr@labstack.com>
2017-08-03 07:52:47 -07:00
Vishal Rana
b42edd791f Closes #980
Signed-off-by: Vishal Rana <vr@labstack.com>
2017-08-02 23:16:11 -07:00
Guilherme Oenning
f8c3008787 Request: New bind property for route parameters (#973)
* bind route params

* rename to bindPathData
2017-07-25 07:22:19 -07:00
Christopher Probst
f3f3e99ba3 Add pointer binding of proper types to DefaultBinder (#915) 2017-04-28 11:07:20 -07:00
Vishal Rana
a216a9319a Bind DELETE params too
Signed-off-by: Vishal Rana <vr@labstack.com>
2017-03-31 21:39:18 -07:00
Vishal Rana
42e83ed0b9 Handle GET request with body
Signed-off-by: Vishal Rana <vr@labstack.com>
2017-03-11 22:42:24 -08:00
Vishal Rana
b218599906 Fixed #864 (#865)
Signed-off-by: Vishal Rana <vr@labstack.com>
2017-02-28 12:04:29 -08:00