Search in sources :

Example 16 with HttpField

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;
}
Also used : Locker(org.eclipse.jetty.util.thread.Locker) HttpField(org.eclipse.jetty.http.HttpField) PreEncodedHttpField(org.eclipse.jetty.http.PreEncodedHttpField) PreEncodedHttpField(org.eclipse.jetty.http.PreEncodedHttpField)

Example 17 with HttpField

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;
}
Also used : HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField) HttpField(org.eclipse.jetty.http.HttpField) HttpFields(org.eclipse.jetty.http.HttpFields) HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField)

Example 18 with HttpField

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;
}
Also used : HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField) HttpField(org.eclipse.jetty.http.HttpField) HttpFields(org.eclipse.jetty.http.HttpFields)

Example 19 with HttpField

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;
}
Also used : Deflater(java.util.zip.Deflater) HttpField(org.eclipse.jetty.http.HttpField)

Example 20 with HttpField

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;
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField) HttpField(org.eclipse.jetty.http.HttpField) HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField)

Aggregations

HttpField (org.eclipse.jetty.http.HttpField)57 Test (org.junit.Test)29 HttpFields (org.eclipse.jetty.http.HttpFields)19 ByteBuffer (java.nio.ByteBuffer)17 MetaData (org.eclipse.jetty.http.MetaData)16 HostPortHttpField (org.eclipse.jetty.http.HostPortHttpField)12 ArrayList (java.util.ArrayList)8 PreEncodedHttpField (org.eclipse.jetty.http.PreEncodedHttpField)7 Entry (org.eclipse.jetty.http2.hpack.HpackContext.Entry)7 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)7 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)7 HttpHeader (org.eclipse.jetty.http.HttpHeader)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)5 HeaderGenerator (org.eclipse.jetty.http2.generator.HeaderGenerator)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 HpackEncoder (org.eclipse.jetty.http2.hpack.HpackEncoder)4 Parser (org.eclipse.jetty.http2.parser.Parser)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3