本文整理汇总了Java中io.netty.util.AsciiString.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java AsciiString.isEmpty方法的具体用法?Java AsciiString.isEmpty怎么用?Java AsciiString.isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.util.AsciiString
的用法示例。
在下文中一共展示了AsciiString.isEmpty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertHeaders
import io.netty.util.AsciiString; //导入方法依赖的package包/类
private static void convertHeaders(HttpHeaders headers, MimeHeaders cHeaders) {
if (headers.isEmpty()) {
return;
}
for (Entry<AsciiString, String> e : headers) {
final AsciiString k = e.getKey();
final String v = e.getValue();
if (k.isEmpty() || k.byteAt(0) == ':') {
continue;
}
final MessageBytes cValue = cHeaders.addValue(k.array(), k.arrayOffset(), k.length());
final byte[] valueBytes = v.getBytes(StandardCharsets.US_ASCII);
cValue.setBytes(valueBytes, 0, valueBytes.length);
}
}
示例2: setHttpResponse
import io.netty.util.AsciiString; //导入方法依赖的package包/类
/**
* The real response sent by netty server
*
* @param response netty defined http response
*/
private void setHttpResponse(HttpResponse response) {
httpResponse = response;
Iterator<Map.Entry<AsciiString, AsciiString>> iterator = headerQueue.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<AsciiString, AsciiString> entry = iterator.next();
AsciiString field = entry.getKey();
AsciiString value = entry.getValue();
if (!field.isEmpty() && !value.isEmpty()) {
httpResponse.headers().set(entry.getKey(), entry.getValue());
}
iterator.remove();
}
httpResponse.headers().add(SET_COOKIE, cookieHeaderQueue);
cookieHeaderQueue.clear();
}
示例3: get
import io.netty.util.AsciiString; //导入方法依赖的package包/类
/**
* Search specified header field for response
*
* @param field http response header field
* @return field value
*/
public String get(AsciiString field) {
if (httpResponse != null) {
return httpResponse.headers().get(field);
}
AsciiString value = headerQueue.get(field);
if (value != null && !value.isEmpty()) {
return value.toString();
}
return null;
}
示例4: toNettyHttp1
import io.netty.util.AsciiString; //导入方法依赖的package包/类
/**
* Translate and add HTTP/2 headers to HTTP/1.x headers.
*
* @param streamId The stream associated with {@code sourceHeaders}.
* @param inputHeaders The HTTP/2 headers to convert.
* @param outputHeaders The object which will contain the resulting HTTP/1.x headers..
* @param httpVersion What HTTP/1.x version {@code outputHeaders} should be treated as
* when doing the conversion.
* @param isTrailer {@code true} if {@code outputHeaders} should be treated as trailing headers.
* {@code false} otherwise.
* @param isRequest {@code true} if the {@code outputHeaders} will be used in a request message.
* {@code false} for response message.
*
* @throws Http2Exception If not all HTTP/2 headers can be translated to HTTP/1.x.
*/
public static void toNettyHttp1(
int streamId, HttpHeaders inputHeaders, io.netty.handler.codec.http.HttpHeaders outputHeaders,
HttpVersion httpVersion, boolean isTrailer, boolean isRequest) throws Http2Exception {
final CharSequenceMap translations = isRequest ? REQUEST_HEADER_TRANSLATIONS
: RESPONSE_HEADER_TRANSLATIONS;
StringJoiner cookieJoiner = null;
try {
for (Entry<AsciiString, String> entry : inputHeaders) {
final AsciiString name = entry.getKey();
final String value = entry.getValue();
AsciiString translatedName = translations.get(name);
if (translatedName != null) {
outputHeaders.add(translatedName, value);
continue;
}
// https://tools.ietf.org/html/rfc7540#section-8.1.2.3
if (name.isEmpty() || HTTP2_TO_HTTP_HEADER_BLACKLIST.contains(name)) {
continue;
}
if (HttpHeaderNames.COOKIE.equals(name)) {
// combine the cookie values into 1 header entry.
// https://tools.ietf.org/html/rfc7540#section-8.1.2.5
if (cookieJoiner == null) {
cookieJoiner = new StringJoiner(COOKIE_SEPARATOR);
}
COOKIE_SPLITTER.split(value).forEach(cookieJoiner::add);
} else {
outputHeaders.add(name, value);
}
}
if (cookieJoiner != null && cookieJoiner.length() != 0) {
outputHeaders.add(HttpHeaderNames.COOKIE, cookieJoiner.toString());
}
} catch (Throwable t) {
throw streamError(streamId, PROTOCOL_ERROR, t, "HTTP/2 to HTTP/1.x headers conversion error");
}
if (!isTrailer) {
HttpUtil.setKeepAlive(outputHeaders, httpVersion, true);
}
}