/** * Adds an additional header to the request * * @param name The name of the header * @param value The value of the header * @return TestResponse instance */ public TestResponse withHeader(String name, String value) { Objects.requireNonNull(name, "name can not be null"); Objects.requireNonNull(value, "value can not be null"); this.httpRequest.header(name, value); return this; }
/** * Simulates a FORM post by setting: * * Content-Type to application/x-www-form-urlencoded * HTTP method to POST * URLEncoding of the given parameters * * @param parameters The parameters to use * @return TestResponse instance */ public TestResponse withForm(Multimap<String, String> parameters) { String form = parameters.entries() .stream() .map(entry -> entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), Charset.forName(Default.ENCODING.toString()))) .collect(Collectors.joining("&")); this.httpRequest.header(CONTENT_TYPE, "application/x-www-form-urlencoded"); this.body = BodyPublishers.ofString(form); this.method = Methods.POST.toString(); return this; }
/** * Sets the ContentType of the request * * @param contentType The content type to use * * @return TestResponse instance */ public TestResponse withContentType(String contentType) { Objects.requireNonNull(contentType, "contentType can not be null"); this.httpRequest.header(CONTENT_TYPE, contentType); return this; }
httpRequestBuilder.header(HeaderNames.COOKIE, cookie.name() + "=" + cookie.value());
protected void setUpHeaders(ReactiveHttpRequest request, HttpRequest.Builder requestBuilder) { request.headers().forEach((key, values) -> values.forEach(value -> requestBuilder.header(key, value))); String contentTypeHeader = getContentTypeHeader(request); if(contentTypeHeader != null) { requestBuilder.header(CONTENT_TYPE_HEADER, contentTypeHeader); } requestBuilder.header(ACCEPT_HEADER, getAcceptHeader()); }