moby/api/server
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
..
backend/build API: add "prune" events 2020-07-28 12:41:14 +02:00
httpstatus errdefs: move GetHTTPErrorStatusCode to api/server/httpstatus 2022-03-21 12:22:39 +01:00
httputils api/server/httputils: add ReadJSON() utility 2022-04-11 21:37:51 +02:00
middleware bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
router api/server/httputils: add ReadJSON() utility 2022-04-11 21:37:51 +02:00
errorhandler.go errdefs: move GetHTTPErrorStatusCode to api/server/httpstatus 2022-03-21 12:22:39 +01:00
middleware.go Add canonical import comment 2018-02-05 16:51:57 -05:00
server.go errdefs: move GetHTTPErrorStatusCode to api/server/httpstatus 2022-03-21 12:22:39 +01:00
server_test.go api/server: use constants for http methods 2019-10-13 17:30:19 +02:00