use of org.eclipse.jetty.http.HttpField in project jetty.project by eclipse.
the class Server method getDateField.
/* ------------------------------------------------------------ */
public HttpField getDateField() {
long now = System.currentTimeMillis();
long seconds = now / 1000;
DateField df = _dateField;
if (df == null || df._seconds != seconds) {
try (Locker.Lock lock = _dateLocker.lock()) {
df = _dateField;
if (df == null || df._seconds != seconds) {
HttpField field = new PreEncodedHttpField(HttpHeader.DATE, DateGenerator.formatDate(now));
_dateField = new DateField(seconds, field);
return field;
}
}
}
return df._dateField;
}
use of org.eclipse.jetty.http.HttpField in project jetty.project by eclipse.
the class ThreadLimitHandler method getForwarded.
private String getForwarded(Request request) {
// Get the right most Forwarded for value.
// This is the value from the closest proxy and the only one that
// can be trusted.
RFC7239 rfc7239 = new RFC7239();
HttpFields httpFields = request.getHttpFields();
for (HttpField field : httpFields) if (_forwardedHeader.equalsIgnoreCase(field.getName()))
rfc7239.addValue(field.getValue());
if (rfc7239.getFor() != null)
return new HostPortHttpField(rfc7239.getFor()).getHost();
return null;
}
use of org.eclipse.jetty.http.HttpField in project jetty.project by eclipse.
the class ThreadLimitHandler method getXForwardedFor.
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;
}
use of org.eclipse.jetty.http.HttpField in project jetty.project by eclipse.
the class GzipHandler method getDeflater.
/* ------------------------------------------------------------ */
@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;
}
if (content_length >= 0 && content_length < _minGzipSize) {
LOG.debug("{} excluded minGzipSize {}", this, request);
return null;
}
// check the accept encoding header
HttpField accept = request.getHttpFields().getField(HttpHeader.ACCEPT_ENCODING);
if (accept == null) {
LOG.debug("{} excluded !accept {}", this, request);
return null;
}
boolean gzip = accept.contains("gzip");
if (!gzip) {
LOG.debug("{} excluded not gzip accept {}", this, request);
return null;
}
Deflater df = _deflater.get();
if (df == null)
df = new Deflater(_compressionLevel, true);
else
_deflater.set(null);
return df;
}
use of org.eclipse.jetty.http.HttpField in project jetty.project by eclipse.
the class Request method findServerName.
/* ------------------------------------------------------------ */
private String findServerName() {
MetaData.Request metadata = _metaData;
// Return host from header field
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) {
HostPortHttpField authority = (HostPortHttpField) host;
metadata.getURI().setAuthority(authority.getHost(), authority.getPort());
return authority.getHost();
}
}
// Return host from connection
String name = getLocalName();
if (name != null)
return name;
// Return the local host
try {
return InetAddress.getLocalHost().getHostAddress();
} catch (java.net.UnknownHostException e) {
LOG.ignore(e);
}
return null;
}
Aggregations