org.glassfish.grizzly.http.util.Header类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中org.glassfish.grizzly.http.util.Header类的一些代码示例,展示了Header类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Header类的具体详情如下:
包路径:org.glassfish.grizzly.http.util.Header
类名称:Header

Header介绍

[英]Enumeration of all headers as defined in RFC 2616.
[中]RFC 2616中定义的所有标头的枚举。

代码示例

代码示例来源:origin: javaee/grizzly

private final boolean handleSetSpecialHeaders(final Header header, final String value) {
  return isSpecialHeaderSet(header.toString()) && setValueBasedOnHeader(header, value);
}

代码示例来源:origin: javaee/grizzly

/**
 * Add the HTTP mime header.
 *
 * @param header the mime {@link Header}.
 * @param value the mime header value.
 */
public final CompressedHeadersBuilder header(Header header, String value) {
  headers.put(header.getLowerCase(), value);
  return this;
}

代码示例来源:origin: javaee/grizzly

private String getValueBasedOnHeader(final Header header) {
  if (Header.ContentType.equals(header)) {
    final String value = getContentType();
    if (value != null) {
      return value;
    }
  } else if (Header.ContentLength.equals(header)) {
    final long value = getContentLength();
    if (value >= 0) {
      return Long.toString(value);
    }
  } else if (Header.Upgrade.equals(header)) {
    return getUpgrade();
  }
  return null;
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-http-server-core

private static void processNormalHeader(final HttpHeader httpHeader,
    final String name, final String value) {
  if (name.equals(Header.Host.getLowerCase())) {
    return;
  }
  final MimeHeaders mimeHeaders = httpHeader.getHeaders();
  final DataChunk valueChunk =
      mimeHeaders.addValue(name);
  validateHeaderCharacters(name, value);
  valueChunk.setString(value);
  finalizeKnownHeader(httpHeader, name, value);
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-http

/**
 * Removes the headers with the given name whose values contain the
 * given string.
 *
 * @param header The name of the {@link Header}s to be removed
 * @param regex The regex string to check the header values against
 */
public void removeHeaderMatches(final Header header, final String regex) {
  for (int i = 0; i < count; i++) {
    if (headers[i].getName().equalsIgnoreCaseLowerCase(
        header.getLowerCaseBytes())
        && getValue(i) != null
        && getValue(i).toString() != null
        && getValue(i).toString().matches(regex)) {
      removeHeader(i--);
    }
  }
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-http-server-core

/**
 * Set internal fields for special header names.
 * Called from set/addHeader.
 * Return true if the header is special, no need to set the header.
 */
private boolean setValueBasedOnHeader(final Header header, final String value) {
  if (Header.ContentType.equals(header)) {
    setContentType(value);
    return true;
  } else if (Header.ContentLength.equals(header)) {
    headers.removeHeader(Header.TransferEncoding);
    setChunked(false);
    return setContentLenth(value);
  } else if (Header.Upgrade.equals(header)) {
    setUpgrade(value);
  } else if (Header.TransferEncoding.equals(header)) {
    if ("chunked".equalsIgnoreCase(value)) {
      setContentLengthLong(-1);
      setChunked(true);
    }
    return true;
  }
  //if (name.equalsIgnoreCase("Content-Language")) {
  //    // TODO XXX XXX Need to construct Locale or something else
  //}
  return false;
}

代码示例来源:origin: javaee/grizzly

protected boolean checkResponseHeadersOnUpgrade(
    final HttpResponsePacket httpResponse) {
  
  if (httpResponse.getStatus() != 101) {
    // Not "HTTP/1.1 101 Switching Protocols"
    return false;
  }
  
  if (!httpResponse.isUpgrade()) {
    // No Upgrade header
    return false;
  }
  
  // Check "Connection: Upgrade, HTTP2-Settings" header
  final DataChunk connectionHeaderDC =
      httpResponse.getHeaders().getValue(Header.Connection);
  return !(connectionHeaderDC == null || connectionHeaderDC.isNull() ||
      !connectionHeaderDC.equals(Header.Upgrade.getBytes()));
}

代码示例来源:origin: javaee/grizzly

public void removeHeader(final Header header) {
  for (int i = 0; i < count; i++) {
    if (headers[i].getName().equalsIgnoreCase(header.getBytes())) {
      removeHeader(i--);
    }
  }
}

代码示例来源:origin: javaee/grizzly

/** Create a new named header , return the MessageBytes
container for the new value
 */
public DataChunk addValue(final Header header) {
  if (!isValidName(header)) {
    return NOOP_CHUNK;
  }
  MimeHeaderField mh = createHeader();
  mh.getName().setBytes(header.toByteArray());
  return mh.getValue();
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-http

/**
 * Allow "set" operations -
 * return a DataChunk container for the
 * header value ( existing header or new
 * if this .
 */
public DataChunk setValue(final Header header) {
  if (!isValidName(header)) {
    return NOOP_CHUNK;
  }
  final byte[] bytes = header.getLowerCaseBytes();
  for (int i = 0; i < count; i++) {
    if (headers[i].getName().equalsIgnoreCaseLowerCase(bytes)) {
      for (int j = i + 1; j < count; j++) {
        if (headers[j].getName().equalsIgnoreCaseLowerCase(bytes)) {
          removeHeader(j--);
        }
      }
      return headers[i].getValue();
    }
  }
  MimeHeaderField mh = createHeader();
  mh.getName().setBytes(header.toByteArray());
  return mh.getValue();
}

代码示例来源:origin: com.ning/async-http-client

private static String authorizationHeaderName(final boolean proxyInd) {
  return proxyInd
      ? Header.ProxyAuthorization.toString()
      : Header.Authorization.toString();
}

代码示例来源:origin: javaee/grizzly

private static Buffer encodeContentEncodingHeader(final MemoryManager memoryManager,
    Buffer buffer, final HttpHeader httpHeader,
    final CacheableDataChunk name, final CacheableDataChunk value) {
  final List<ContentEncoding> packetContentEncodings =
      httpHeader.getContentEncodings(true);
  name.setBytes(Header.ContentEncoding.toByteArray());
  value.reset();
  httpHeader.extractContentEncoding(value);
  boolean needComma = !value.isNull();
  final byte[] tempBuffer = httpHeader.getTempHeaderEncodingBuffer();
  
  buffer = encodeMimeHeader(memoryManager, buffer, name, value, tempBuffer, false);
  for (ContentEncoding encoding : packetContentEncodings) {
    if (needComma) {
      buffer = put(memoryManager, buffer, Constants.COMMA);
    }
    
    buffer = put(memoryManager, buffer, tempBuffer, encoding.getName());
    needComma = true;
  }
  buffer = put(memoryManager, buffer, CRLF_BYTES);
  
  return buffer;
}

代码示例来源:origin: com.ning/async-http-client

private static Request newRequest(final HttpTransactionContext ctx,
    final Uri newUri, final HttpResponsePacket response,
    final Realm realm, boolean asGet) {
  final Request prototype = ctx.getAhcRequest();
  final FluentCaseInsensitiveStringsMap prototypeHeaders =
      prototype.getHeaders();
  
  prototypeHeaders.remove(Header.Host.toString());
  prototypeHeaders.remove(Header.ContentLength.toString());
  
  if (asGet)
    prototypeHeaders.remove(Header.ContentType.toString());
  if (realm != null && realm.getScheme() == AuthScheme.NTLM) {
    prototypeHeaders.remove(Header.Authorization.toString());
    prototypeHeaders.remove(Header.ProxyAuthorization.toString());
  }
  
  final RequestBuilder builder = new RequestBuilder(prototype);
  if (asGet) {
    builder.setMethod("GET");
  }
  builder.setUrl(newUri.toString());
  for (String cookieStr : response.getHeaders().values(Header.SetCookie)) {
    builder.addOrReplaceCookie(CookieDecoder.decode(cookieStr));
  }
      
  return builder.build();
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-http

/**
 * Finds and returns a header field with the given name.  If no such
 * field exists, null is returned.  If more than one such field is
 * in the header, an arbitrary one is returned.
 */
public DataChunk getValue(final Header header) {
  final byte[] bytes = header.getLowerCaseBytes();
  for (int i = 0; i < count; i++) {
    if (headers[i].getName().equalsIgnoreCaseLowerCase(bytes)) {
      return headers[i].getValue();
    }
  }
  return null;
}

代码示例来源:origin: javaee/grizzly

private final String handleGetSpecialHeader(final Header header) {
  return ((isSpecialHeader(header.toString())) ? getValueBasedOnHeader(header) : null);
}

代码示例来源:origin: javaee/grizzly

private static void processNormalHeader(final HttpHeader httpHeader,
    final String name, final String value) {
  if (name.equals(Header.Host.getLowerCase())) {
    return;
  }
  final MimeHeaders mimeHeaders = httpHeader.getHeaders();
  final DataChunk valueChunk =
      mimeHeaders.addValue(name);
  validateHeaderCharacters(name, value);
  valueChunk.setString(value);
  finalizeKnownHeader(httpHeader, name, value);
}

代码示例来源:origin: javaee/grizzly

/**
 * Removes the headers with the given name whose values contain the
 * given string.
 *
 * @param header The name of the {@link Header}s to be removed
 * @param regex The regex string to check the header values against
 */
public void removeHeaderMatches(final Header header, final String regex) {
  for (int i = 0; i < count; i++) {
    if (headers[i].getName().equalsIgnoreCaseLowerCase(
        header.getLowerCaseBytes())
        && getValue(i) != null
        && getValue(i).toString() != null
        && getValue(i).toString().matches(regex)) {
      removeHeader(i--);
    }
  }
}

代码示例来源:origin: javaee/grizzly

/**
 * Set internal fields for special header names.
 * Called from set/addHeader.
 * Return true if the header is special, no need to set the header.
 */
private boolean setValueBasedOnHeader(final Header header, final String value) {
  if (Header.ContentType.equals(header)) {
    setContentType(value);
    return true;
  } else if (Header.ContentLength.equals(header)) {
    headers.removeHeader(Header.TransferEncoding);
    setChunked(false);
    return setContentLenth(value);
  } else if (Header.Upgrade.equals(header)) {
    setUpgrade(value);
  } else if (Header.TransferEncoding.equals(header)) {
    if ("chunked".equalsIgnoreCase(value)) {
      setContentLengthLong(-1);
      setChunked(true);
    }
    return true;
  }
  //if (name.equalsIgnoreCase("Content-Language")) {
  //    // TODO XXX XXX Need to construct Locale or something else
  //}
  return false;
}

代码示例来源:origin: javaee/grizzly

protected boolean checkResponseHeadersOnUpgrade(
    final HttpResponsePacket httpResponse) {
  
  if (httpResponse.getStatus() != 101) {
    // Not "HTTP/1.1 101 Switching Protocols"
    return false;
  }
  
  if (!httpResponse.isUpgrade()) {
    // No Upgrade header
    return false;
  }
  
  // Check "Connection: Upgrade, HTTP2-Settings" header
  final DataChunk connectionHeaderDC =
      httpResponse.getHeaders().getValue(Header.Connection);
  return !(connectionHeaderDC == null || connectionHeaderDC.isNull() ||
      !connectionHeaderDC.equals(Header.Upgrade.getBytes()));
}

代码示例来源:origin: javaee/grizzly

public void removeHeader(final Header header) {
  for (int i = 0; i < count; i++) {
    if (headers[i].getName().equalsIgnoreCase(header.getBytes())) {
      removeHeader(i--);
    }
  }
}

相关文章