All Downloads are FREE. Search and download functionalities are using the official Maven repository.

htmlcompiler.model.httpmock.Request Maven / Gradle / Ivy

package htmlcompiler.model.httpmock;

import com.sun.net.httpserver.HttpHandler;

import java.util.List;

import static java.nio.charset.StandardCharsets.UTF_8;

public final class Request {

    public final Endpoint endpoint;
    private final int statusCode;
    private final List
headers; private final String body; public Request(final Endpoint endpoint, final int statusCode, final List
headers, final String body) { this.endpoint = endpoint; this.statusCode = statusCode; this.headers = headers; this.body = body; } private static class Header { private final String name; private final String value; private Header(final String name, final String value) { this.name = name; this.value = value; } } public static HttpHandler toHttpHandler(final Request request) { return exchange -> { for (final Header header : request.headers) { exchange.getResponseHeaders().add(header.name, header.value); } exchange.sendResponseHeaders(request.statusCode, request.body.length()); exchange.getResponseBody().write(request.body.getBytes(UTF_8)); exchange.close(); }; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy