use of org.eclipse.jetty.http.HttpHeaderValue in project jetty.project by eclipse.
the class HttpChannelOverHttp method parsedHeader.
@Override
public void parsedHeader(HttpField field) {
HttpHeader header = field.getHeader();
String value = field.getValue();
if (header != null) {
switch(header) {
case CONNECTION:
_connection = field;
break;
case HOST:
if (!_metadata.getURI().isAbsolute() && field instanceof HostPortHttpField) {
HostPortHttpField hp = (HostPortHttpField) field;
_metadata.getURI().setAuthority(hp.getHost(), hp.getPort());
}
break;
case EXPECT:
{
if (_metadata.getHttpVersion() == HttpVersion.HTTP_1_1) {
HttpHeaderValue expect = HttpHeaderValue.CACHE.get(value);
switch(expect == null ? HttpHeaderValue.UNKNOWN : expect) {
case CONTINUE:
_expect100Continue = true;
break;
case PROCESSING:
_expect102Processing = true;
break;
default:
String[] values = field.getValues();
for (int i = 0; values != null && i < values.length; i++) {
expect = HttpHeaderValue.CACHE.get(values[i].trim());
if (expect == null)
_unknownExpectation = true;
else {
switch(expect) {
case CONTINUE:
_expect100Continue = true;
break;
case PROCESSING:
_expect102Processing = true;
break;
default:
_unknownExpectation = true;
}
}
}
}
}
break;
}
case UPGRADE:
_upgrade = field;
break;
default:
break;
}
}
_fields.add(field);
}
use of org.eclipse.jetty.http.HttpHeaderValue in project jetty.project by eclipse.
the class Response method reset.
public void reset(boolean preserveCookies) {
resetForForward();
_status = 200;
_reason = null;
_contentLength = -1;
List<HttpField> cookies = preserveCookies ? _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) {
for (String value : StringUtil.csvSplit(null, connection, 0, connection.length())) {
HttpHeaderValue cb = HttpHeaderValue.CACHE.get(value);
if (cb != null) {
switch(cb) {
case CLOSE:
_fields.put(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.toString());
break;
case KEEP_ALIVE:
if (HttpVersion.HTTP_1_0.is(_channel.getRequest().getProtocol()))
_fields.put(HttpHeader.CONNECTION, HttpHeaderValue.KEEP_ALIVE.toString());
break;
case TE:
_fields.put(HttpHeader.CONNECTION, HttpHeaderValue.TE.toString());
break;
default:
}
}
}
}
if (preserveCookies)
cookies.forEach(f -> _fields.add(f));
else {
Request request = getHttpChannel().getRequest();
HttpSession session = request.getSession(false);
if (session != null && session.isNew()) {
SessionHandler sh = request.getSessionHandler();
if (sh != null) {
HttpCookie c = sh.getSessionCookie(session, request.getContextPath(), request.isSecure());
if (c != null)
addCookie(c);
}
}
}
}
Aggregations