Java Code Examples for io.undertow.util.HeaderValues#size()
The following examples show how to use
io.undertow.util.HeaderValues#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResponseHeaderAttribute.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public String readAttribute(final HttpServerExchange exchange) { HeaderValues header = exchange.getResponseHeaders().get(responseHeader); if (header == null) { return null; } else if(header.size() == 1) { return header.getFirst(); } StringBuilder sb = new StringBuilder(); sb.append("["); for (int i = 0; i < header.size(); ++i) { if (i != 0) { sb.append(", "); } sb.append(header.get(i)); } sb.append("]"); return sb.toString(); }
Example 2
Source File: RequestHeaderAttribute.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public String readAttribute(final HttpServerExchange exchange) { HeaderValues header = exchange.getRequestHeaders().get(requestHeader); if (header == null) { return null; } else if(header.size() == 1) { return header.getFirst(); } StringBuilder sb = new StringBuilder(); sb.append("["); for (int i = 0; i < header.size(); ++i) { if (i != 0) { sb.append(", "); } sb.append(header.get(i)); } sb.append("]"); return sb.toString(); }
Example 3
Source File: DomainUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private static String determineMimeType(OperationResponse.StreamEntry entry, HttpServerExchange exchange) { // We see if the type provided by the response "matches" the ACCEPT header; if yes, use it // If not, use application/octet-stream to trigger the browser to treat it as a download String entryType = entry.getMimeType(); HeaderValues headerValues = exchange.getRequestHeaders().get(Headers.ACCEPT); if (headerValues == null || headerValues.size() == 0) { // The browser doesn't care return entryType; } String wildCard = null; int slash = entryType.indexOf('/'); if (slash > 0) { wildCard = entryType.substring(0, slash) + "/*"; } for (String acceptable : headerValues) { if ("*/*".equals(acceptable) || acceptable.contains(entryType) || (wildCard != null && acceptable.contains(wildCard))) { return entryType; } } return "application/octet-stream"; }
Example 4
Source File: JsonContentHandler.java From divolte-collector with Apache License 2.0 | 6 votes |
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { final HeaderValues contentType = exchange.getRequestHeaders().get(Headers.CONTENT_TYPE); if (null != contentType && contentType.size() == 1 && contentType.getFirst().toLowerCase(Locale.ROOT).equals("application/json")) { next.handleRequest(exchange); } else { exchange.setStatusCode(StatusCodes.UNSUPPORTED_MEDIA_TYPE); exchange.getResponseHeaders() .put(Headers.CONTENT_TYPE, "text/plain; charset=utf-8"); exchange.getResponseSender() .send("Content type must be application/json.", StandardCharsets.UTF_8); exchange.endExchange(); } }
Example 5
Source File: DatawaveAuthenticationMechanism.java From datawave with Apache License 2.0 | 5 votes |
private String getSingleHeader(HeaderMap headers, String headerName) throws MultipleHeaderException { String value = null; HeaderValues values = (headers == null) ? null : headers.get(headerName); if (values != null) { if (values.size() > 1) throw new MultipleHeaderException(headerName + " was specified multiple times, which is not allowed!"); value = values.getFirst(); } return value; }
Example 6
Source File: Connectors.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Verifies that the provided request headers are valid according to rfc7230. In particular: * - At most one content-length or transfer encoding */ public static boolean areRequestHeadersValid(HeaderMap headers) { HeaderValues te = headers.get(Headers.TRANSFER_ENCODING); HeaderValues cl = headers.get(Headers.CONTENT_LENGTH); if(te != null && cl != null) { return false; } else if(te != null && te.size() > 1) { return false; } else if(cl != null && cl.size() > 1) { return false; } return true; }