Refine search
@Override public Map<String, String> toSingleValueMap() { Map<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size()); Iterator<HttpField> iterator = this.headers.iterator(); iterator.forEachRemaining(field -> { if (!singleValueMap.containsKey(field.getName())) { singleValueMap.put(field.getName(), field.getValue()); } }); return singleValueMap; }
private static void processResponseHeaders(final HttpFields respHeaders, final ClientResponse jerseyResponse) { for (final HttpField header : respHeaders) { final String headerName = header.getName(); final MultivaluedMap<String, String> headers = jerseyResponse.getHeaders(); List<String> list = headers.get(headerName); if (list == null) { list = new ArrayList<>(); } list.add(header.getValue()); headers.put(headerName, list); } }
if (!HttpMethod.GET.is(method) && !HttpMethod.POST.is(method) && !HttpMethod.HEAD.is(method)) baseRequest.setHandled(true); return; return; LOG.warn("No error page "+error_page); LOG.warn(Log.EXCEPTION, e); return; if (LOG.isDebugEnabled()) LOG.debug("No Error Page mapping for request({} {}) (using default)",request.getMethod(),request.getRequestURI()); baseRequest.setHandled(true); HttpField accept = baseRequest.getHttpFields().getField(HttpHeader.ACCEPT); if (accept == null || accept.contains("text/html") || accept.contains("*/*"))
final MetaData.Response response=(info instanceof MetaData.Response)?(MetaData.Response)info:null; HttpField field = fields.getField(f); HttpHeader h = field.getHeader(); if (h==null) putTo(field,header); content_length = field.getLongValue(); else if (content_length!=field.getLongValue()) throw new BadMessageException(INTERNAL_SERVER_ERROR_500,String.format("Incorrect Content-Length %d!=%d",content_length,field.getLongValue())); content_length_field = true; break; chunked_hint = field.contains(HttpHeaderValue.CHUNKED.asString()); if (field.contains(HttpHeaderValue.CLOSE.asString())) if (info.getHttpVersion() == HttpVersion.HTTP_1_0 && _persistent==null && field.contains(HttpHeaderValue.KEEP_ALIVE.asString())) else if (transfer_encoding.toString().endsWith(HttpHeaderValue.CHUNKED.toString())) putTo(new HttpField(HttpHeader.TRANSFER_ENCODING,transfer_encoding.getValue()+",chunked"),header); transfer_encoding = null; String v = transfer_encoding.getValue(); int c = v.lastIndexOf(','); if (c>0 && v.lastIndexOf(HttpHeaderValue.CHUNKED.toString(),c)>c) putTo(new HttpField(HttpHeader.TRANSFER_ENCODING,v.substring(0,c).trim()),header);
@Override public String toString() { try { StringBuilder buffer = new StringBuilder(); for (HttpField field : this) { if (field != null) { String tmp = field.getName(); if (tmp != null) buffer.append(tmp); buffer.append(": "); tmp = field.getValue(); if (tmp != null) buffer.append(tmp); buffer.append("\r\n"); } } buffer.append("\r\n"); return buffer.toString(); } catch (Exception e) { LOG.warn(e); return e.toString(); } }
public boolean upgrade(Request request) { if (HttpMethod.PRI.is(request.getMethod())) { getParser().directUpgrade(); } else { HttpField settingsField = request.getFields().getField(HttpHeader.HTTP2_SETTINGS); if (settingsField == null) throw new BadMessageException("Missing " + HttpHeader.HTTP2_SETTINGS + " header"); String value = settingsField.getValue(); final byte[] settings = B64Code.decodeRFC4648URL(value == null ? "" : value); if (LOG.isDebugEnabled()) LOG.debug("{} settings {}",this,TypeUtil.toHexString(settings)); SettingsFrame settingsFrame = SettingsBodyParser.parseBody(BufferUtil.toBuffer(settings)); if (settingsFrame == null) { LOG.warn("Invalid {} header value: {}", HttpHeader.HTTP2_SETTINGS, value); throw new BadMessageException(); } getParser().standardUpgrade(); upgradeFrames.add(new PrefaceFrame()); upgradeFrames.add(settingsFrame); // Remember the request to send a response from onOpen(). upgradeFrames.add(new HeadersFrame(1, new Request(request), null, true)); } return true; }
if (LOG.isDebugEnabled()) LOG.debug("upgrade {} {}",this,_upgrade); if (_upgrade!=PREAMBLE_UPGRADE_H2C && (_connection==null || !_connection.contains("upgrade"))) throw new BadMessageException(HttpStatus.BAD_REQUEST_400); if (f.getProtocols().contains(_upgrade.getValue())) if (LOG.isDebugEnabled()) LOG.debug("No factory for {} in {}",_upgrade,getConnector()); return false; HttpFields response101 = new HttpFields(); Connection upgrade_connection = factory.upgradeConnection(getConnector(),getEndPoint(),_metadata,response101); if (upgrade_connection==null) if (LOG.isDebugEnabled()) LOG.debug("Upgrade from {} to {}", getEndPoint().getConnection(),upgrade_connection); getRequest().setAttribute(HttpConnection.UPGRADE_CONNECTION_ATTRIBUTE,upgrade_connection); getResponse().setStatus(101); getHttpTransport().onCompleted();
?_fields.stream() .filter(f->f.getHeader()==HttpHeader.SET_COOKIE) .collect(Collectors.toList()):null; _fields.clear(); String connection = _channel.getRequest().getHeader(HttpHeader.CONNECTION.asString()); if (connection != null) _fields.put(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.toString()); break; if (HttpVersion.HTTP_1_0.is(_channel.getRequest().getProtocol())) _fields.put(HttpHeader.CONNECTION, HttpHeaderValue.KEEP_ALIVE.toString()); break; HttpSession session = request.getSession(false); if (session!=null && session.isNew())
public Entry add(HttpField field) { Entry entry=new Entry(field); int size = entry.getSize(); if (size>_maxDynamicTableSizeInBytes) { if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] !added size %d>%d",hashCode(),size,_maxDynamicTableSizeInBytes)); _dynamicTable.evictAll(); return null; } _dynamicTableSizeInBytes+=size; _dynamicTable.add(entry); _fieldMap.put(field,entry); _nameMap.put(StringUtil.asciiToLowerCase(field.getName()),entry); if (LOG.isDebugEnabled()) LOG.debug(String.format("HdrTbl[%x] added %s",hashCode(),entry)); _dynamicTable.evict(); return entry; }
@Override public boolean parsedHeader(HttpField field) HttpHeader header=field.getHeader(); String value=field.getValue(); if (value == null) value = ""; String charset = (mime == null || mime.getCharset() == null) ? MimeTypes.getCharsetFromContentType(value) : mime.getCharset().toString(); if (charset != null) _request.setCharacterEncodingUnchecked(charset); break; if (field.getName()!=null) _request.getHttpFields().add(field); return false;
@Override public Deflater getDeflater(Request request, long content_length) String ua = request.getHttpFields().get(HttpHeader.USER_AGENT); if (ua!=null && !isAgentGzipable(ua)) LOG.debug("{} excluded user agent {}",this,request); return null; LOG.debug("{} excluded minGzipSize {}",this,request); return null; HttpField accept = request.getHttpFields().getField(HttpHeader.ACCEPT_ENCODING); LOG.debug("{} excluded !accept {}",this,request); return null; boolean gzip = accept.contains("gzip");
protected void storeCookie(URI uri, HttpField field) { try { String value = field.getValue(); if (value != null) { Map<String, List<String>> header = new HashMap<>(1); header.put(field.getHeader().asString(), Collections.singletonList(value)); getHttpDestination().getHttpClient().getCookieManager().put(uri, header); } } catch (IOException x) { if (LOG.isDebugEnabled()) LOG.debug(x); } }
?_fields.stream() .filter(f->f.getHeader()==HttpHeader.SET_COOKIE) .collect(Collectors.toList()):null; _fields.clear(); String connection = _channel.getRequest().getHeader(HttpHeader.CONNECTION.asString()); if (connection != null) _fields.put(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.toString()); break; if (HttpVersion.HTTP_1_0.is(_channel.getRequest().getProtocol())) _fields.put(HttpHeader.CONNECTION, HttpHeaderValue.KEEP_ALIVE.toString()); break; HttpSession session = request.getSession(false); if (session!=null && session.isNew())
private void storeCookie(URI uri, HttpField field) { try { Map<String, List<String>> header = new HashMap<>(1); header.put(field.getHeader().asString(), Collections.singletonList(field.getValue())); connection.getHttpClient().getCookieManager().put(uri, header); } catch (IOException x) { LOG.debug(x); } }
HttpField host = metadata==null?null:metadata.getFields().getField(HttpHeader.HOST); if (host!=null) if (!(host instanceof HostPortHttpField) && host.getValue()!=null && !host.getValue().isEmpty()) host=new HostPortHttpField(host.getValue()); if (host instanceof HostPortHttpField) String name=getLocalName(); if (name != null) return name; LOG.ignore(e);
public void emit(HttpField field) throws HpackException.SessionException HttpHeader header = field.getHeader(); String name = field.getName(); String value = field.getValue(); int field_size = name.length() + (value == null ? 0 : value.length()); _size+=field_size+32; _status = field.getIntValue(); _response = true; break; _authority = new AuthorityHttpField(value); _fields.add(field); break; _contentLength = field.getLongValue(); _fields.add(field); break; _fields.add(field); else streamException("Unsupported TE value '%s'", value);
private String getXForwardedFor(Request request) { // Get the right most XForwarded-For for value. // This is the value from the closest proxy and the only one that // can be trusted. String forwarded_for = null; HttpFields httpFields = request.getHttpFields(); for (HttpField field : httpFields) if (_forwardedHeader.equalsIgnoreCase(field.getName())) forwarded_for = field.getValue(); if (forwarded_for==null || forwarded_for.isEmpty()) return null; int comma = forwarded_for.lastIndexOf(','); return (comma>=0)?forwarded_for.substring(comma+1).trim():forwarded_for; }