moby--moby/api/server/router
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
..
build api/server: build: refactor for better readability 2019-12-04 16:19:01 +01:00
checkpoint api/server/httputils: add ReadJSON() utility 2022-04-11 21:37:51 +02:00
container api/server/httputils: add ReadJSON() utility 2022-04-11 21:37:51 +02:00
debug
distribution Remove more of registry v1 code. 2021-02-23 09:49:46 +01:00
grpc grpc: make sure typed errors handler is installed 2021-04-26 22:38:59 -07:00
image search: remove parsing JSON filters out of the backend 2022-03-18 09:44:55 +01:00
network api/server/httputils: add ReadJSON() utility 2022-04-11 21:37:51 +02:00
plugin api/server/httputils: add ReadJSON() utility 2022-04-11 21:37:51 +02:00
session move /session api endpoint out of experimental 2018-08-21 22:43:34 +00:00
swarm api/server/httputils: add ReadJSON() utility 2022-04-11 21:37:51 +02:00
system API: add "Swarm" header to _ping endpoint 2022-03-25 23:54:14 +01:00
volume api/server/httputils: add ReadJSON() utility 2022-04-11 21:37:51 +02:00
experimental.go fix typos 2018-09-01 21:26:38 +08:00
local.go api/server/router: use consts for HTTP methods 2019-11-26 21:55:29 +01:00
router.go