private void sendResponse(ChannelHandlerContext ctx, FullHttpResponse httpResponse) { boolean close = false; try { ctx.write(httpResponse); ctx.flush(); } catch (Exception e) { LoggerUtil.error("NettyHttpHandler write response fail.", e); close = true; } finally { // close connection if (close || httpResponse == null || !HttpHeaderValues.KEEP_ALIVE.equals(httpResponse.headers().get(HttpHeaderNames.CONNECTION))) { ctx.close(); } } }
/** * Compares a {@code CharSequence} to this {@code String} to determine if their contents are equal. * * @param a the character sequence to compare to. * @return {@code true} if equal, otherwise {@code false} */ public boolean contentEquals(CharSequence a) { if (a == null || a.length() != length()) { return false; } if (a.getClass() == AsciiString.class) { return equals(a); } for (int i = arrayOffset(), j = 0; j < a.length(); ++i, ++j) { if (b2c(value[i]) != a.charAt(j)) { return false; } } return true; }
/** * Compares a {@code CharSequence} to this {@code String} to determine if their contents are equal. * * @param a the character sequence to compare to. * @return {@code true} if equal, otherwise {@code false} */ public boolean contentEquals(CharSequence a) { if (a == null || a.length() != length()) { return false; } if (a.getClass() == AsciiString.class) { return equals(a); } for (int i = arrayOffset(), j = 0; j < a.length(); ++i, ++j) { if (b2c(value[i]) != a.charAt(j)) { return false; } } return true; }
@Override public boolean equals(Object o) { if (!(o instanceof WebSocketScheme)) { return false; } WebSocketScheme other = (WebSocketScheme) o; return other.port() == port && other.name().equals(name); }
@Override public boolean equals(Object o) { if (!(o instanceof HttpScheme)) { return false; } HttpScheme other = (HttpScheme) o; return other.port() == port && other.name().equals(name); }
/** * Compares a {@code CharSequence} to this {@code String} to determine if their contents are equal. * * @param a the character sequence to compare to. * @return {@code true} if equal, otherwise {@code false} */ public boolean contentEquals(CharSequence a) { if (a == null || a.length() != length()) { return false; } if (a.getClass() == AsciiString.class) { return equals(a); } for (int i = arrayOffset(), j = 0; j < a.length(); ++i, ++j) { if (b2c(value[i]) != a.charAt(j)) { return false; } } return true; }
public void translate(Entry<CharSequence, CharSequence> entry) throws Http2Exception { final CharSequence name = entry.getKey(); final CharSequence value = entry.getValue(); AsciiString translatedName = translations.get(name); if (translatedName != null) { output.add(translatedName, AsciiString.of(value)); } else if (!Http2Headers.PseudoHeaderName.isPseudoHeader(name)) { // https://tools.ietf.org/html/rfc7540#section-8.1.2.3 // All headers that start with ':' are only valid in HTTP/2 context if (name.length() == 0 || name.charAt(0) == ':') { throw streamError(streamId, PROTOCOL_ERROR, "Invalid HTTP/2 header '%s' encountered in translation to HTTP/1.x", name); } if (COOKIE.equals(name)) { // combine the cookie values into 1 header entry. // https://tools.ietf.org/html/rfc7540#section-8.1.2.5 String existingCookie = output.get(COOKIE); output.set(COOKIE, (existingCookie != null) ? (existingCookie + "; " + value) : value); } else { output.add(name, value); } } } }
/** * Converts the specified Netty HTTP/2 into Armeria HTTP/2 headers. */ public static HttpHeaders toArmeria(Http2Headers headers, boolean endOfStream) { final HttpHeaders converted = new DefaultHttpHeaders(false, headers.size(), endOfStream); StringJoiner cookieJoiner = null; for (Entry<CharSequence, CharSequence> e : headers) { final AsciiString name = HttpHeaderNames.of(e.getKey()); final CharSequence value = e.getValue(); // Cookies must be concatenated into a single octet string. // https://tools.ietf.org/html/rfc7540#section-8.1.2.5 if (name.equals(HttpHeaderNames.COOKIE)) { if (cookieJoiner == null) { cookieJoiner = new StringJoiner(COOKIE_SEPARATOR); } COOKIE_SPLITTER.split(value).forEach(cookieJoiner::add); } else { converted.add(name, convertHeaderValue(name, value)); } } if (cookieJoiner != null && cookieJoiner.length() != 0) { converted.add(HttpHeaderNames.COOKIE, cookieJoiner.toString()); } return converted; }
if (HttpHeaderNames.COOKIE.equals(name)) {
if (name.equals(HttpHeaderNames.FORWARDED)) { addr = getFirstValidAddress( headers.get(HttpHeaderNames.FORWARDED), FORWARDED_CONVERTER, filter);
CharSequence value = headers.get(HttpHeaderNames.EXPECT); if (options.isHandle100ContinueAutomatically() && ((value != null && HttpHeaderValues.CONTINUE.equals(value)) || headers.contains(HttpHeaderNames.EXPECT, HttpHeaderValues.CONTINUE))) { req.response().writeContinue();
/** * Compares a {@code CharSequence} to this {@code String} to determine if their contents are equal. * * @param a the character sequence to compare to. * @return {@code true} if equal, otherwise {@code false} */ public boolean contentEquals(CharSequence a) { if (a == null || a.length() != length()) { return false; } if (a.getClass() == AsciiString.class) { return equals(a); } for (int i = arrayOffset(), j = 0; j < a.length(); ++i, ++j) { if (b2c(value[i]) != a.charAt(j)) { return false; } } return true; }
CharSequence value = headers.get(HttpHeaderNames.EXPECT); if (options.isHandle100ContinueAutomatically() && ((value != null && HttpHeaderValues.CONTINUE.equals(value)) || headers.contains(HttpHeaderNames.EXPECT, HttpHeaderValues.CONTINUE))) { req.response().writeContinue();
@Override public boolean equals(Object o) { if (!(o instanceof HttpScheme)) { return false; } HttpScheme other = (HttpScheme) o; return other.port() == port && other.name().equals(name); }
@Override public boolean equals(Object o) { if (!(o instanceof HttpScheme)) { return false; } HttpScheme other = (HttpScheme) o; return other.port() == port && other.name().equals(name); }
@Override public boolean equals(Object o) { if (!(o instanceof WebSocketScheme)) { return false; } WebSocketScheme other = (WebSocketScheme) o; return other.port() == port && other.name().equals(name); }
@Override public boolean equals(Object o) { if (!(o instanceof WebSocketScheme)) { return false; } WebSocketScheme other = (WebSocketScheme) o; return other.port() == port && other.name().equals(name); }
@Override public boolean equals(Object o) { if (!(o instanceof WebSocketScheme)) { return false; } WebSocketScheme other = (WebSocketScheme) o; return other.port() == port && other.name().equals(name); }
@Override public boolean equals(Object o) { if (!(o instanceof HttpScheme)) { return false; } HttpScheme other = (HttpScheme) o; return other.port() == port && other.name().equals(name); }