moby/integration/network
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
..
ipvlan Update to Go 1.17.0, and gofmt with Go 1.17 2021-08-24 23:33:27 +02:00
macvlan Update to Go 1.17.0, and gofmt with Go 1.17 2021-08-24 23:33:27 +02:00
delete_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
dns_test.go integration/network: remove IsUserNamespace in favor of testenv equivalent 2021-08-12 09:12:04 +02:00
helpers.go Update to Go 1.17.0, and gofmt with Go 1.17 2021-08-24 23:33:27 +02:00
helpers_windows.go integration/network: remove IsUserNamespace in favor of testenv equivalent 2021-08-12 09:12:04 +02:00
inspect_test.go test-integration: support more rootless tests 2020-03-16 17:37:38 +09:00
main_test.go testutil: make testing packages public 2019-09-11 07:47:23 -05:00
network_test.go api/server/httputils: add ReadJSON() utility 2022-04-11 21:37:51 +02:00
service_test.go integration/libnetwork: make delInterface() a t.Helper() 2021-08-20 13:33:13 +02:00