Search in sources :

Example 56 with MetaData

use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.

the class ContinuationBodyParser method onHeaders.

private void onHeaders() {
    ByteBuffer headerBlock = headerBlockFragments.complete();
    MetaData metaData = headerBlockParser.parse(headerBlock, headerBlock.remaining());
    HeadersFrame frame = new HeadersFrame(getStreamId(), metaData, headerBlockFragments.getPriorityFrame(), headerBlockFragments.isEndStream());
    notifyHeaders(frame);
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) ByteBuffer(java.nio.ByteBuffer) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame)

Example 57 with MetaData

use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.

the class HeaderBlockParser method parse.

public MetaData parse(ByteBuffer buffer, int blockLength) {
    // We must wait for the all the bytes of the header block to arrive.
    // If they are not all available, accumulate them.
    // When all are available, decode them.
    int accumulated = blockBuffer == null ? 0 : blockBuffer.position();
    int remaining = blockLength - accumulated;
    if (buffer.remaining() < remaining) {
        if (blockBuffer == null) {
            blockBuffer = byteBufferPool.acquire(blockLength, false);
            BufferUtil.clearToFill(blockBuffer);
        }
        blockBuffer.put(buffer);
        return null;
    } else {
        int limit = buffer.limit();
        buffer.limit(buffer.position() + remaining);
        ByteBuffer toDecode;
        if (blockBuffer != null) {
            blockBuffer.put(buffer);
            BufferUtil.flipToFlush(blockBuffer, 0);
            toDecode = blockBuffer;
        } else {
            toDecode = buffer;
        }
        MetaData result = hpackDecoder.decode(toDecode);
        buffer.limit(limit);
        if (blockBuffer != null) {
            byteBufferPool.release(blockBuffer);
            blockBuffer = null;
        }
        return result;
    }
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) ByteBuffer(java.nio.ByteBuffer)

Example 58 with MetaData

use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.

the class HeadersBodyParser method emptyBody.

@Override
protected void emptyBody(ByteBuffer buffer) {
    if (hasFlag(Flags.END_HEADERS)) {
        MetaData metaData = headerBlockParser.parse(BufferUtil.EMPTY_BUFFER, 0);
        onHeaders(0, 0, false, metaData);
    } else {
        headerBlockFragments.setStreamId(getStreamId());
        headerBlockFragments.setEndStream(isEndStream());
        if (hasFlag(Flags.PRIORITY))
            connectionFailure(buffer, ErrorCode.PROTOCOL_ERROR.code, "invalid_headers_priority_frame");
    }
}
Also used : MetaData(org.eclipse.jetty.http.MetaData)

Example 59 with MetaData

use of org.eclipse.jetty.http.MetaData in project jetty.project by eclipse.

the class Request method getLocales.

/* ------------------------------------------------------------ */
/*
     * @see javax.servlet.ServletRequest#getLocales()
     */
@Override
public Enumeration<Locale> getLocales() {
    MetaData.Request metadata = _metaData;
    if (metadata == null)
        return Collections.enumeration(__defaultLocale);
    List<String> acceptable = metadata.getFields().getQualityCSV(HttpHeader.ACCEPT_LANGUAGE);
    // handle no locale
    if (acceptable.isEmpty())
        return Collections.enumeration(__defaultLocale);
    List<Locale> locales = acceptable.stream().map(language -> {
        language = HttpFields.stripParameters(language);
        String country = "";
        int dash = language.indexOf('-');
        if (dash > -1) {
            country = language.substring(dash + 1).trim();
            language = language.substring(0, dash).trim();
        }
        return new Locale(language, country);
    }).collect(Collectors.toList());
    return Collections.enumeration(locales);
}
Also used : Attributes(org.eclipse.jetty.util.Attributes) Enumeration(java.util.Enumeration) ServletException(javax.servlet.ServletException) Context(org.eclipse.jetty.server.handler.ContextHandler.Context) UrlEncoded(org.eclipse.jetty.util.UrlEncoded) MultiPartInputStreamParser(org.eclipse.jetty.util.MultiPartInputStreamParser) InetAddress(java.net.InetAddress) AsyncListener(javax.servlet.AsyncListener) Locale(java.util.Locale) MetaData(org.eclipse.jetty.http.MetaData) Map(java.util.Map) HttpStatus(org.eclipse.jetty.http.HttpStatus) HttpSession(javax.servlet.http.HttpSession) Collection(java.util.Collection) RequestDispatcher(javax.servlet.RequestDispatcher) ServletRequestAttributeEvent(javax.servlet.ServletRequestAttributeEvent) ServletRequestAttributeListener(javax.servlet.ServletRequestAttributeListener) IO(org.eclipse.jetty.util.IO) MultipartConfigElement(javax.servlet.MultipartConfigElement) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) EventListener(java.util.EventListener) List(java.util.List) Principal(java.security.Principal) ServletResponse(javax.servlet.ServletResponse) URIUtil(org.eclipse.jetty.util.URIUtil) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MimeTypes(org.eclipse.jetty.http.MimeTypes) BadMessageException(org.eclipse.jetty.http.BadMessageException) AttributesMap(org.eclipse.jetty.util.AttributesMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpScheme(org.eclipse.jetty.http.HttpScheme) ServletInputStream(javax.servlet.ServletInputStream) HttpVersion(org.eclipse.jetty.http.HttpVersion) Session(org.eclipse.jetty.server.session.Session) StringUtil(org.eclipse.jetty.util.StringUtil) ArrayList(java.util.ArrayList) HttpUpgradeHandler(javax.servlet.http.HttpUpgradeHandler) AsyncContext(javax.servlet.AsyncContext) HttpHeader(org.eclipse.jetty.http.HttpHeader) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpURI(org.eclipse.jetty.http.HttpURI) Charset(java.nio.charset.Charset) Cookie(javax.servlet.http.Cookie) HttpFields(org.eclipse.jetty.http.HttpFields) ServletRequest(javax.servlet.ServletRequest) HttpCookie(org.eclipse.jetty.http.HttpCookie) MultiMap(org.eclipse.jetty.util.MultiMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) InputStreamReader(java.io.InputStreamReader) File(java.io.File) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField) HttpMethod(org.eclipse.jetty.http.HttpMethod) Part(javax.servlet.http.Part) HttpField(org.eclipse.jetty.http.HttpField) Log(org.eclipse.jetty.util.log.Log) DispatcherType(javax.servlet.DispatcherType) ServletContext(javax.servlet.ServletContext) BufferedReader(java.io.BufferedReader) Logger(org.eclipse.jetty.util.log.Logger) Collections(java.util.Collections) ServletRequestWrapper(javax.servlet.ServletRequestWrapper) InputStream(java.io.InputStream) Locale(java.util.Locale) MetaData(org.eclipse.jetty.http.MetaData)

Example 60 with MetaData

use of org.eclipse.jetty.http.MetaData 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

MetaData (org.eclipse.jetty.http.MetaData)99 HttpFields (org.eclipse.jetty.http.HttpFields)87 Test (org.junit.Test)79 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)75 CountDownLatch (java.util.concurrent.CountDownLatch)64 Stream (org.eclipse.jetty.http2.api.Stream)61 Session (org.eclipse.jetty.http2.api.Session)59 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)57 FuturePromise (org.eclipse.jetty.util.FuturePromise)51 ByteBuffer (java.nio.ByteBuffer)39 HttpServletResponse (javax.servlet.http.HttpServletResponse)36 Promise (org.eclipse.jetty.util.Promise)36 DataFrame (org.eclipse.jetty.http2.frames.DataFrame)35 Callback (org.eclipse.jetty.util.Callback)30 HTTP2Session (org.eclipse.jetty.http2.HTTP2Session)29 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)26 IOException (java.io.IOException)24 HashMap (java.util.HashMap)24 HttpServletRequest (javax.servlet.http.HttpServletRequest)24 ServletException (javax.servlet.ServletException)23