Search in sources :

Example 1 with HttpHeaderValue

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

Example 2 with HttpHeaderValue

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);
            }
        }
    }
}
Also used : HttpScheme(org.eclipse.jetty.http.HttpScheme) HttpVersion(org.eclipse.jetty.http.HttpVersion) CookieCompliance(org.eclipse.jetty.http.CookieCompliance) StringUtil(org.eclipse.jetty.util.StringUtil) HttpHeader(org.eclipse.jetty.http.HttpHeader) HttpURI(org.eclipse.jetty.http.HttpURI) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServletOutputStream(javax.servlet.ServletOutputStream) Locale(java.util.Locale) MetaData(org.eclipse.jetty.http.MetaData) IllegalSelectorException(java.nio.channels.IllegalSelectorException) HttpStatus(org.eclipse.jetty.http.HttpStatus) Cookie(javax.servlet.http.Cookie) RuntimeIOException(org.eclipse.jetty.io.RuntimeIOException) HttpFields(org.eclipse.jetty.http.HttpFields) EnumSet(java.util.EnumSet) PrintWriter(java.io.PrintWriter) HttpSession(javax.servlet.http.HttpSession) HttpContent(org.eclipse.jetty.http.HttpContent) HttpHeaderValue(org.eclipse.jetty.http.HttpHeaderValue) QuotedStringTokenizer(org.eclipse.jetty.util.QuotedStringTokenizer) Collection(java.util.Collection) RequestDispatcher(javax.servlet.RequestDispatcher) HttpCookie(org.eclipse.jetty.http.HttpCookie) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Collectors(java.util.stream.Collectors) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) List(java.util.List) Syntax(org.eclipse.jetty.http.Syntax) HttpField(org.eclipse.jetty.http.HttpField) PreEncodedHttpField(org.eclipse.jetty.http.PreEncodedHttpField) Log(org.eclipse.jetty.util.log.Log) HttpGenerator(org.eclipse.jetty.http.HttpGenerator) URIUtil(org.eclipse.jetty.util.URIUtil) Logger(org.eclipse.jetty.util.log.Logger) DateGenerator(org.eclipse.jetty.http.DateGenerator) Collections(java.util.Collections) MimeTypes(org.eclipse.jetty.http.MimeTypes) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HttpField(org.eclipse.jetty.http.HttpField) PreEncodedHttpField(org.eclipse.jetty.http.PreEncodedHttpField) HttpSession(javax.servlet.http.HttpSession) HttpCookie(org.eclipse.jetty.http.HttpCookie) HttpHeaderValue(org.eclipse.jetty.http.HttpHeaderValue)

Aggregations

HttpHeader (org.eclipse.jetty.http.HttpHeader)2 HttpHeaderValue (org.eclipse.jetty.http.HttpHeaderValue)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 IllegalSelectorException (java.nio.channels.IllegalSelectorException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Locale (java.util.Locale)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 Cookie (javax.servlet.http.Cookie)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 CookieCompliance (org.eclipse.jetty.http.CookieCompliance)1 DateGenerator (org.eclipse.jetty.http.DateGenerator)1 HostPortHttpField (org.eclipse.jetty.http.HostPortHttpField)1