HTTPRequest { public void body(byte[] body, ContentType contentType) { this.body = body; this.contentType = contentType; headers.put(HTTPHeaders.CONTENT_TYPE, contentType.toString()); } HTTPRequest(HTTPMethod method, String uri); void accept(ContentType contentType); void basicAuth(String user, String password); void bearerAuth(String token); void body(byte[] body, ContentType contentType); void body(String body, ContentType contentType); void form(Map<String, String> form); String requestURI(); final HTTPMethod method; final Map<String, String> params; final Map<String, String> headers; public String uri; public byte[] body; public ContentType contentType; public Map<String, String> form; public Duration connectTimeout; public Duration timeout; public Duration slowOperationThreshold; }
@Test void body() { var request = new HTTPRequest(HTTPMethod.POST, "http: request.body("text", ContentType.TEXT_PLAIN); assertThat(request.method).isEqualTo(HTTPMethod.POST); assertThat(request.contentType).isEqualTo(ContentType.TEXT_PLAIN); assertThat(request.headers).containsEntry(HTTPHeaders.CONTENT_TYPE, "text/plain; charset=utf-8"); assertThat(request.body).isEqualTo(Strings.bytes("text")); }