Java Code Examples for io.undertow.util.HttpString#equals()

The following examples show how to use io.undertow.util.HttpString#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpTransferEncoding.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static StreamSinkConduit handleExplicitTransferEncoding(HttpServerExchange exchange, StreamSinkConduit channel, ConduitListener<StreamSinkConduit> finishListener, HeaderMap responseHeaders, String transferEncodingHeader, boolean headRequest) {
    HttpString transferEncoding = new HttpString(transferEncodingHeader);
    if (transferEncoding.equals(Headers.CHUNKED)) {
        if (headRequest) {
            return channel;
        }
        Boolean preChunked = exchange.getAttachment(HttpAttachments.PRE_CHUNKED_RESPONSE);
        if(preChunked != null && preChunked) {
            return new PreChunkedStreamSinkConduit(channel, finishListener, exchange);
        } else {
            return new ChunkedStreamSinkConduit(channel, exchange.getConnection().getByteBufferPool(), true, !exchange.isPersistent(), responseHeaders, finishListener, exchange);
        }
    } else {

        if (headRequest) {
            return channel;
        }
        log.trace("Cancelling persistence because response is identity with no content length");
        // make it not persistent - very unfortunate for the next request handler really...
        exchange.setPersistent(false);
        responseHeaders.put(Headers.CONNECTION, Headers.CLOSE.toString());
        return new FinishableStreamSinkConduit(channel, terminateResponseListener(exchange));
    }
}
 
Example 2
Source File: HttpServletResponseImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void setHeader(final HttpString name, final String value) {
    if(name == null) {
        throw UndertowServletMessages.MESSAGES.headerNameWasNull();
    }
    if (insideInclude || ignoredFlushPerformed) {
        return;
    }
    if(name.equals(Headers.CONTENT_TYPE)) {
        setContentType(value);
    } else {
        exchange.getResponseHeaders().put(name, value);
    }
}
 
Example 3
Source File: HttpServletResponseImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void addHeader(final HttpString name, final String value) {
    if(name == null) {
        throw UndertowServletMessages.MESSAGES.headerNameWasNull();
    }
    if (insideInclude || ignoredFlushPerformed || treatAsCommitted) {
        return;
    }
    if(name.equals(Headers.CONTENT_TYPE) && !exchange.getResponseHeaders().contains(Headers.CONTENT_TYPE)) {
        setContentType(value);
    } else {
        exchange.getResponseHeaders().add(name, value);
    }
}
 
Example 4
Source File: Http2HeaderBlockParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void emitHeader(HttpString name, String value, boolean neverIndex) throws HpackException {
    if(maxHeaderListSize > 0) {
        headerSize += (name.length() + value.length() + 32);
        if (headerSize > maxHeaderListSize) {
            throw new HpackException(UndertowMessages.MESSAGES.headerBlockTooLarge(), Http2Channel.ERROR_PROTOCOL_ERROR);
        }
    }
    if(maxHeaders > 0 && headerMap.size() > maxHeaders) {
        return;
    }
    headerMap.add(name, value);

    if(name.length() == 0) {
        throw UndertowMessages.MESSAGES.invalidHeader();
    }
    if(name.equals(Headers.TRANSFER_ENCODING)) {
        throw new HpackException(Http2Channel.ERROR_PROTOCOL_ERROR);
    }
    if(name.byteAt(0) == ':') {
        if(client) {
            if(!name.equals(Http2Channel.STATUS)) {
                invalid = true;
            }
        } else {
            if(!SERVER_HEADERS.contains(name)) {
                invalid = true;
            }
        }
        if(!processingPseudoHeaders) {
            throw new HpackException(UndertowMessages.MESSAGES.pseudoHeaderInWrongOrder(name), Http2Channel.ERROR_PROTOCOL_ERROR);
        }
    } else {
        processingPseudoHeaders = false;
    }
    for(int i = 0; i < name.length(); ++i) {
        byte c = name.byteAt(i);
        if(c>= 'A' && c <= 'Z') {
            invalid = true;
            UndertowLogger.REQUEST_LOGGER.debugf("Malformed request, header %s contains uppercase characters", name);
        } else if(c != ':' && !Connectors.isValidTokenCharacter(c)) {
            invalid = true;
            UndertowLogger.REQUEST_LOGGER.debugf("Malformed request, header %s contains invalid token character", name);
        }
    }

}