public HttpRequest build() {
        String scheme = this.scheme != null ? this.scheme : "http";
        String hostname = this.hostname != null ? this.hostname : "localhost";
        StringBuilder uriBuilder = new StringBuilder(scheme).append("://").append(hostname);
        if (port > 0) uriBuilder.append(':').append(port);
        uriBuilder.append(path);
        if (queryParameters.size() > 0) {
            uriBuilder.append('?');
            queryParameters.forEach((name, values) -> {
                for (String value : values) {
                    uriBuilder.append(name).append('=').append(value).append('&');
                }
            });
            int lastIndex = uriBuilder.length() - 1;
            if (uriBuilder.charAt(lastIndex) == '&') {
                uriBuilder.setLength(lastIndex);
            }
        }
        HttpRequest request;
        if (content != null) {
            request = HttpRequest.createTestRequest(uriBuilder.toString(), method, content);
        } else {
            request = HttpRequest.createTestRequest(uriBuilder.toString(), method);
        }
        headers.forEach((name, value) -> request.getJDiscRequest().headers().put(name, value));
        if (principal != null) request.getJDiscRequest().setUserPrincipal(principal);
        if (socketAddress != null) request.getJDiscRequest().setRemoteAddress(socketAddress);
        request.getJDiscRequest().context().putAll(attributes);
        return request;
    }
Builder for creating a {@link HttpRequest} to be used in test context

@author bjorncs
container-core/src/main/java/com/yahoo/container/jdisc/HttpRequestBuilder.java