1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration/plugin
Sebastiaan van Stijn 0c9ff0b45a
api/server/httputils: add ReadJSON() utility
Implement a ReadJSON() utility to help reduce some code-duplication,
and to make sure we handle JSON requests consistently (e.g. always
check for the content-type).

Differences compared to current handling:

- prevent possible panic if request.Body is nil ("should never happen")
- always require Content-Type to be "application/json"
- be stricter about additional content after JSON (previously ignored)
- but, allow the body to be empty (an empty body is not invalid);
  update TestContainerInvalidJSON accordingly, which was testing the
  wrong expectation.
- close body after reading (some code did this)

We should consider to add a "max body size" on this function, similar to
7b9275c0da/api/server/middleware/debug.go (L27-L40)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-11 21:37:51 +02:00
..
authz refactor: move from io/ioutil to io and os package 2021-08-27 14:56:57 +08:00
common api/server/httputils: add ReadJSON() utility 2022-04-11 21:37:51 +02:00
graphdriver Finish refactor of UID/GID usage to a new struct 2022-03-14 16:28:57 -04:00
logging refactor: move from io/ioutil to io and os package 2021-08-27 14:56:57 +08:00
volumes refactor: move from io/ioutil to io and os package 2021-08-27 14:56:57 +08:00
pkg_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00