Search in sources :

Example 1 with DefaultHTTPRequestBody

use of com.github.ljtfreitas.julian.http.DefaultHTTPRequestBody in project julian-http-client by ljtfreitas.

the class MapMultipartFormHTTPRequestWriter method write.

@Override
public HTTPRequestBody write(Map<String, ?> map, Charset encoding) {
    String boundary = boundaryGen.run();
    MediaType mediaType = MediaType.MULTIPART_FORM_DATA.parameter("boundary", boundary);
    return new DefaultHTTPRequestBody(mediaType, () -> serialize(map, encoding, "----" + boundary));
}
Also used : MediaType(com.github.ljtfreitas.julian.http.MediaType) DefaultHTTPRequestBody(com.github.ljtfreitas.julian.http.DefaultHTTPRequestBody)

Example 2 with DefaultHTTPRequestBody

use of com.github.ljtfreitas.julian.http.DefaultHTTPRequestBody in project julian-http-client by ljtfreitas.

the class DebugHTTPClientTest method show.

@Test
void show(@Mock HTTPRequest<String> httpRequest) {
    mockServer.when(request("/debug").withMethod("POST").withBody("request body")).respond(response().withStatusCode(200).withContentType(TEXT_PLAIN).withHeader("x-some-header", "some-content").withBody("it works!"));
    DebugHTTPClient debugHTTPClient = new DebugHTTPClient(new DefaultHTTPClient());
    when(httpRequest.path()).thenReturn(URI.create("http://localhost:8090/debug"));
    when(httpRequest.method()).thenReturn(HTTPMethod.POST);
    when(httpRequest.headers()).thenReturn(new HTTPHeaders(List.of(new HTTPHeader("X-Some-Header", "some-content"), new HTTPHeader("Accept", "text/plain"))));
    when(httpRequest.body()).thenReturn(Optional.of(new DefaultHTTPRequestBody(MediaType.TEXT_PLAIN, () -> BodyPublishers.ofString("request body"))));
    HTTPClientRequest intercepted = debugHTTPClient.request(httpRequest);
    intercepted.execute().join().unsafe();
    verify(httpRequest, atLeastOnce()).path();
    verify(httpRequest, atLeastOnce()).headers();
    verify(httpRequest, atLeastOnce()).method();
}
Also used : HTTPHeaders(com.github.ljtfreitas.julian.http.HTTPHeaders) DefaultHTTPRequestBody(com.github.ljtfreitas.julian.http.DefaultHTTPRequestBody) HTTPHeader(com.github.ljtfreitas.julian.http.HTTPHeader) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultHTTPRequestBody (com.github.ljtfreitas.julian.http.DefaultHTTPRequestBody)2 HTTPHeader (com.github.ljtfreitas.julian.http.HTTPHeader)1 HTTPHeaders (com.github.ljtfreitas.julian.http.HTTPHeaders)1 MediaType (com.github.ljtfreitas.julian.http.MediaType)1 Test (org.junit.jupiter.api.Test)1