/** * Adds one header to match which can specified using plain strings or regular expressions * (for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html) * * @param name the header name * @param values the header values which can be a varags of strings or regular expressions */ public HttpRequest withHeader(String name, String... values) { this.headers.withEntry(header(name, values)); return this; }
public static Header header(NottableString name, Collection<NottableString> value) { return new Header(name, value); } }
@Override public String serialize(int numberOfSpacesToIndent, Header header) { StringBuilder output = new StringBuilder(); output.append(NEW_LINE).append(Strings.padStart("", numberOfSpacesToIndent * INDENT_SIZE, ' ')); output.append("new Header(").append(NottableStringToJavaSerializer.serializeNottableString(header.getName())); for (NottableString value : header.getValues()) { output.append(", ").append(NottableStringToJavaSerializer.serializeNottableString(value)); } output.append(")"); return output.toString(); }
Headers headers = new Headers(); for (Header header : httpResponse.getHeaderList()) { if (!headersToIgnore.contains(header.getName().getValue().toLowerCase())) { if (header.getName().getValue().equalsIgnoreCase(CONTENT_TYPE.toString())) { for (NottableString value : new ArrayList<NottableString>(header.getValues())) { header.getValues().clear(); header.addValues(value.getValue().replace(";charset", "; charset")); header = header(header.getName().lowercase(), header.getValues());
public HttpRequest onRequest(HttpRequest request) { if (request != null) { List<String> headersToRemove = Arrays.asList( "proxy-connection", "connection", "keep-alive", "transfer-encoding", "te", "trailer", "proxy-authorization", "proxy-authenticate", "upgrade" ); Headers headers = new Headers(); for (Header header : request.getHeaderList()) { if (!headersToRemove.contains(header.getName().getValue().toLowerCase(Locale.ENGLISH))) { headers.withEntry(header); } } HttpRequest clonedRequest = request.clone(); if (!headers.isEmpty()) { clonedRequest.withHeaders(headers); } return clonedRequest; } else { return null; } } }
public HttpRequest onRequest(HttpRequest request) { if (request != null) { List<String> headersToRemove = Arrays.asList( "proxy-connection", "connection", "keep-alive", "transfer-encoding", "te", "trailer", "proxy-authorization", "proxy-authenticate", "upgrade" ); Headers headers = new Headers(); for (Header header : request.getHeaderList()) { if (!headersToRemove.contains(header.getName().getValue().toLowerCase(Locale.ENGLISH))) { headers.withEntry(header); } } HttpRequest clonedRequest = request.clone(); if (!headers.isEmpty()) { clonedRequest.withHeaders(headers); } return clonedRequest; } else { return null; } } }
/** * Add a header to return as a Header object, if a header with * the same name already exists this will NOT be modified but * two headers will exist * * @param name the header name as a NottableString * @param values the header values which can be a varags of NottableStrings */ public HttpResponse withHeader(NottableString name, NottableString... values) { this.headers.withEntry(header(name, values)); return this; }
@Override public Header build(NottableString name, List<NottableString> values) { return new Header(name, values); }
private void setHeaders(HttpResponse httpResponse, HttpServletResponse httpServletResponse) { if (httpResponse.getHeaderList() != null) { for (Header header : httpResponse.getHeaderList()) { String headerName = header.getName().getValue(); if (!headerName.equalsIgnoreCase(CONTENT_LENGTH.toString()) && !headerName.equalsIgnoreCase(TRANSFER_ENCODING.toString()) && !headerName.equalsIgnoreCase(HOST.toString()) && !headerName.equalsIgnoreCase(ACCEPT_ENCODING.toString()) && !headerName.equalsIgnoreCase(CONNECTION.toString())) { for (NottableString value : header.getValues()) { httpServletResponse.addHeader(headerName, value.getValue()); } } } } addContentTypeHeader(httpResponse, httpServletResponse); }
/** * Adds one header to match on or to not match on using the NottableString, each NottableString can either be a positive matching value, * such as string("match"), or a value to not match on, such as not("do not match"), the string values passed to the NottableString * can also be a plain string or a regex (for more details of the supported regex syntax * see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html) * * @param name the header name as a NottableString * @param values the header values which can be a varags of NottableStrings */ public HttpRequest withHeader(NottableString name, NottableString... values) { this.headers.withEntry(header(name, values)); return this; }
public static Header header(String name, String... value) { return new Header(name, value); }
for (NottableString headerValue : header.getValues()) { curlString.append(" -H '").append(header.getName().getValue()).append(": ").append(headerValue.getValue()).append("'"); if (header.getName().getValue().toLowerCase().contains("Accept-Encoding".toLowerCase())) { if (headerValue.getValue().toLowerCase().contains("gzip") || headerValue.getValue().toLowerCase().contains("deflate")
@Override public void writeResponse(HttpRequest request, HttpResponseStatus responseStatus, String body, String contentType) { HttpResponse response = response() .withStatusCode(responseStatus.code()) .withBody(body); if (body != null && !body.isEmpty()) { response.replaceHeader(header(CONTENT_TYPE.toString(), contentType + "; charset=utf-8")); } writeResponse(request, response, true); }
public static Header header(NottableString name, NottableString... value) { return new Header(name, value); }
private void setCookies(HttpResponse httpResponse) { Cookies cookies = new Cookies(); for (Header header : httpResponse.getHeaderList()) { if (header.getName().getValue().equalsIgnoreCase("Set-Cookie")) { for (NottableString cookieHeader : header.getValues()) { io.netty.handler.codec.http.cookie.Cookie httpCookie = ClientCookieDecoder.LAX.decode(cookieHeader.getValue()); String name = httpCookie.name().trim(); String value = httpCookie.value().trim(); cookies.withEntry(new Cookie(name, value)); } } if (header.getName().getValue().equalsIgnoreCase("Cookie")) { for (NottableString cookieHeader : header.getValues()) { for (io.netty.handler.codec.http.cookie.Cookie httpCookie : ServerCookieDecoder.LAX.decode(cookieHeader.getValue())) { String name = httpCookie.name().trim(); String value = httpCookie.value().trim(); cookies.withEntry(new Cookie(name, value)); } } } } if (!cookies.isEmpty()) { httpResponse.withCookies(cookies); } }
@Override public void writeResponse(HttpRequest request, HttpResponseStatus responseStatus, String body, String contentType) { HttpResponse response = response() .withStatusCode(responseStatus.code()) .withReasonPhrase(responseStatus.reasonPhrase()) .withBody(body); if (body != null && !body.isEmpty()) { response.replaceHeader(header(CONTENT_TYPE.toString(), contentType + "; charset=utf-8")); } writeResponse(request, response, true); }
public static Header header(String name, Collection<String> value) { return new Header(name, value); }
private void setHeader(HttpRequest httpRequest, FullHttpRequest request) { for (Header header : httpRequest.getHeaderList()) { String headerName = header.getName().getValue(); && !headerName.equalsIgnoreCase(HOST.toString()) && !headerName.equalsIgnoreCase(ACCEPT_ENCODING.toString())) { if (!header.getValues().isEmpty()) { for (NottableString headerValue : header.getValues()) { request.headers().add(headerName, headerValue.getValue());
protected void addConnectionHeader(HttpRequest request, HttpResponse response) { ConnectionOptions connectionOptions = response.getConnectionOptions(); if (connectionOptions != null && connectionOptions.getKeepAliveOverride() != null) { if (connectionOptions.getKeepAliveOverride()) { response.replaceHeader(header(CONNECTION.toString(), KEEP_ALIVE.toString())); } else { response.replaceHeader(header(CONNECTION.toString(), CLOSE.toString())); } } else if (connectionOptions == null || isFalseOrNull(connectionOptions.getSuppressConnectionHeader())) { if (request.isKeepAlive() != null && request.isKeepAlive() && (connectionOptions == null || isFalseOrNull(connectionOptions.getCloseSocket()))) { response.replaceHeader(header(CONNECTION.toString(), KEEP_ALIVE.toString())); } else { response.replaceHeader(header(CONNECTION.toString(), CLOSE.toString())); } } } }
public static Header header(String name, int value) { return new Header(name, String.valueOf(value)); }