org.apache.tomcat.util.http.MimeHeaders Java Examples

The following examples show how to use org.apache.tomcat.util.http.MimeHeaders. 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: Http2TestBase.java    From Tomcat8-Source-Read with MIT License 7 votes vote down vote up
protected void buildGetRequest(byte[] frameHeader, ByteBuffer headersPayload, byte[] padding,
        List<Header> headers, int streamId) {
    if (padding != null) {
        headersPayload.put((byte) (0xFF & padding.length));
    }
    MimeHeaders mimeHeaders = new MimeHeaders();
    for (Header header : headers) {
        mimeHeaders.addValue(header.getName()).setString(header.getValue());
    }
    hpackEncoder.encode(mimeHeaders, headersPayload);
    if (padding != null) {
        headersPayload.put(padding);
    }
    headersPayload.flip();

    ByteUtil.setThreeBytes(frameHeader, 0, headersPayload.limit());
    frameHeader[3] = FrameType.HEADERS.getIdByte();
    // Flags. end of headers (0x04). end of stream (0x01)
    frameHeader[4] = 0x05;
    if (padding != null) {
        frameHeader[4] += 0x08;
    }
    // Stream id
    ByteUtil.set31Bits(frameHeader, 5, streamId);
}
 
Example #2
Source File: TestHttp2Limits.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private void populateHeadersPayload(ByteBuffer headersPayload, List<String[]> customHeaders,
        String path) throws Exception {
    MimeHeaders headers = new MimeHeaders();
    headers.addValue(":method").setString("GET");
    headers.addValue(":scheme").setString("http");
    headers.addValue(":path").setString(path);
    headers.addValue(":authority").setString("localhost:" + getPort());
    for (String[] customHeader : customHeaders) {
        headers.addValue(customHeader[0]).setString(customHeader[1]);
    }
    State state = hpackEncoder.encode(headers, headersPayload);
    if (state != State.COMPLETE) {
        throw new Exception("Unable to build headers");
    }
    headersPayload.flip();

    log.debug("Headers payload generated of size [" + headersPayload.limit() + "]");
}
 
Example #3
Source File: BSTAuthenticatorTest.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
@Test(description = "This test case tests the canHandle method of the BSTAuthenticator under faulty conditions")
public void testCanHandleWithFalseConditions() throws IllegalAccessException {
    Request request = new Request();
    org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
    request.setCoyoteRequest(coyoteRequest);
    Assert.assertFalse(bstAuthenticator.canHandle(request),
            "BST Authenticator can handle a request without content type");

    MimeHeaders mimeHeaders = new MimeHeaders();
    MessageBytes bytes = mimeHeaders.addValue("content-type");
    bytes.setString("test");
    headersField.set(coyoteRequest, mimeHeaders);
    request.setCoyoteRequest(coyoteRequest);
    Assert.assertFalse(bstAuthenticator.canHandle(request),
            "BST Authenticator can handle a request with content type test");
}
 
Example #4
Source File: TestHpack.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test(expected=HpackException.class)
public void testExcessiveStringLiteralPadding() throws Exception {
    MimeHeaders headers = new MimeHeaders();
    headers.setValue("X-test").setString("foobar");
    ByteBuffer output = ByteBuffer.allocate(512);
    HpackEncoder encoder = new HpackEncoder();
    encoder.encode(headers, output);
    // Hack the output buffer to extend the EOS marker for the header value
    // by another byte
    output.array()[7] = (byte) -122;
    output.put((byte) -1);
    output.flip();
    MimeHeaders headers2 = new MimeHeaders();
    HpackDecoder decoder = new HpackDecoder();
    decoder.setHeaderEmitter(new HeadersListener(headers2));
    decoder.decode(output);
}
 
Example #5
Source File: BSTAuthenticatorTest.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
/**
 * To create a soap request by reading the request from given file.
 *
 * @param fileName Name of the file that has the soap request content.
 * @return Request created with soap content.
 * @throws IllegalAccessException Illegal Access Exception.
 * @throws IOException            IO Exception.
 */
private Request createSoapRequest(String fileName) throws IllegalAccessException, IOException {
    Request request = new Request();
    ClassLoader classLoader = getClass().getClassLoader();
    URL resourceUrl = classLoader
            .getResource("requests" + File.separator + "BST" + File.separator + fileName);
    String bstRequestContent = null;
    if (resourceUrl != null) {
        File bst = new File(resourceUrl.getFile());
        bstRequestContent = FileUtils.readFileToString(bst);
    }
    org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
    MimeHeaders mimeHeaders = new MimeHeaders();
    MessageBytes bytes = mimeHeaders.addValue("content-type");
    bytes.setString("application/xml");
    bytes = mimeHeaders.addValue("custom");
    bytes.setString(bstRequestContent);
    headersField.set(coyoteRequest, mimeHeaders);
    TestInputBuffer inputBuffer = new TestInputBuffer();
    coyoteRequest.setInputBuffer(inputBuffer);
    Context context = new StandardContext();
    request.setContext(context);
    request.setCoyoteRequest(coyoteRequest);
    return request;
}
 
Example #6
Source File: TestHpack.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testDecode() throws Exception {
    MimeHeaders headers = new MimeHeaders();
    headers.setValue("header1").setString("value1");
    headers.setValue(":status").setString("200");
    headers.setValue("header2").setString("value2");
    ByteBuffer output = ByteBuffer.allocate(512);
    HpackEncoder encoder = new HpackEncoder();
    encoder.encode(headers, output);
    output.flip();
    MimeHeaders headers2 = new MimeHeaders();
    HpackDecoder decoder = new HpackDecoder();
    decoder.setHeaderEmitter(new HeadersListener(headers2));
    decoder.decode(output);
    // Redo (table is supposed to be updated)
    output.clear();
    encoder.encode(headers, output);
    output.flip();
    headers2.recycle();
    Assert.assertEquals(3, output.remaining());
    // Check that the decoder is using the table right
    decoder.decode(output);
    Assert.assertEquals("value2", headers2.getHeader("header2"));
}
 
Example #7
Source File: TestHpack.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testEncode() throws Exception {
    MimeHeaders headers = new MimeHeaders();
    headers.setValue("header1").setString("value1");
    headers.setValue(":status").setString("200");
    headers.setValue("header2").setString("value2");
    ByteBuffer output = ByteBuffer.allocate(512);
    HpackEncoder encoder = new HpackEncoder();
    encoder.encode(headers, output);
    output.flip();
    // Size is supposed to be 33 without huffman, or 27 with it
    // TODO: use the HpackHeaderFunction to enable huffman predictably
    Assert.assertEquals(27, output.remaining());
    output.clear();
    encoder.encode(headers, output);
    output.flip();
    // Size is now 3 after using the table
    Assert.assertEquals(3, output.remaining());
}
 
Example #8
Source File: Http2TestBase.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
protected void buildSimpleGetRequestPart2(byte[] frameHeader, ByteBuffer headersPayload,
        List<Header> headers, int streamId) {
    MimeHeaders mimeHeaders = new MimeHeaders();
    for (Header header : headers) {
        mimeHeaders.addValue(header.getName()).setString(header.getValue());
    }
    hpackEncoder.encode(mimeHeaders, headersPayload);

    headersPayload.flip();

    ByteUtil.setThreeBytes(frameHeader, 0, headersPayload.limit());
    frameHeader[3] = FrameType.CONTINUATION.getIdByte();
    // Flags. end of headers (0x04)
    frameHeader[4] = 0x04;
    // Stream id
    ByteUtil.set31Bits(frameHeader, 5, streamId);
}
 
Example #9
Source File: Http2TestBase.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
protected void buildSimpleGetRequestPart1(byte[] frameHeader, ByteBuffer headersPayload,
        List<Header> headers, int streamId) {
    MimeHeaders mimeHeaders = new MimeHeaders();
    for (Header header : headers) {
        mimeHeaders.addValue(header.getName()).setString(header.getValue());
    }
    hpackEncoder.encode(mimeHeaders, headersPayload);

    headersPayload.flip();

    ByteUtil.setThreeBytes(frameHeader, 0, headersPayload.limit());
    frameHeader[3] = FrameType.HEADERS.getIdByte();
    // Flags. end of stream (0x01)
    frameHeader[4] = 0x01;
    // Stream id
    ByteUtil.set31Bits(frameHeader, 5, streamId);
}
 
Example #10
Source File: JWTAuthenticatorTest.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
/**
 * To create a JWT request with the given jwt header.
 *  @param jwtToken JWT token to be added to the header
 * @param requestUri Request URI to be added to the request.
 */
private Request createJWTRequest(String jwtToken, String requestUri)
        throws IllegalAccessException, NoSuchFieldException {
    Request request = new Request();
    org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
    MimeHeaders mimeHeaders = new MimeHeaders();
    MessageBytes bytes = mimeHeaders.addValue(JWT_HEADER);
    bytes.setString(jwtToken);
    headersField.set(coyoteRequest, mimeHeaders);
    Field uriMB = org.apache.coyote.Request.class.getDeclaredField("uriMB");
    uriMB.setAccessible(true);
    bytes = MessageBytes.newInstance();
    bytes.setString(requestUri);
    uriMB.set(coyoteRequest, bytes);
    request.setCoyoteRequest(coyoteRequest);
    return request;
}
 
Example #11
Source File: BasicAuthAuthenticatorTest.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
@Test(description = "This method tests the behaviour of canHandle method when different wrong values given for a "
        + "request")
public void testCanHandleWithoutRequireParameters()
        throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException,
        InvocationTargetException, InstantiationException {
    request = new Request();
    context = new StandardContext();
    request.setContext(context);
    Assert.assertFalse(basicAuthAuthenticator.canHandle(request),
            "Without proper headers and parameters, the request can be handled by BasicAuthAuthenticator.");
    context.addParameter("basicAuth", "true");
    request.setContext(context);
    Assert.assertFalse(basicAuthAuthenticator.canHandle(request),
            "Without proper Authentication headers request can be handled by BasicAuthAuthenticator.");
    coyoteRequest = new org.apache.coyote.Request();
    mimeHeaders = new MimeHeaders();
    bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
    bytes.setString("test");
    headersField.set(coyoteRequest, mimeHeaders);
    request.setCoyoteRequest(coyoteRequest);
    Assert.assertFalse(basicAuthAuthenticator.canHandle(request),
            "With a different authorization header Basic Authenticator can handle the request");
}
 
Example #12
Source File: BasicAuthAuthenticatorTest.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
@Test(description = "This method tests the behaviour of the authenticate method in BasicAuthenticator with valid "
        + "credentials", dependsOnMethods = "testCanHandleWithRequireParameters")
public void testAuthenticateWithValidCredentials() throws EncoderException, IllegalAccessException {
    String encodedString = new String(Base64.getEncoder().encode((ADMIN_USER + ":" + ADMIN_USER).getBytes()));
    request = new Request();
    context = new StandardContext();
    context.addParameter("basicAuth", "true");
    request.setContext(context);
    mimeHeaders = new MimeHeaders();
    bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
    bytes.setString(BASIC_HEADER + encodedString);
    coyoteRequest = new org.apache.coyote.Request();
    headersField.set(coyoteRequest, mimeHeaders);
    request.setCoyoteRequest(coyoteRequest);
    AuthenticationInfo authenticationInfo = basicAuthAuthenticator.authenticate(request, null);
    Assert.assertEquals(authenticationInfo.getStatus(), WebappAuthenticator.Status.CONTINUE,
            "For a valid user authentication failed.");
    Assert.assertEquals(authenticationInfo.getUsername(), ADMIN_USER,
            "Authenticated username for from BasicAuthenticator is not matching with the original user.");
    Assert.assertEquals(authenticationInfo.getTenantDomain(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME,
            "Authenticated user's tenant domain from BasicAuthenticator is not matching with the "
                    + "original user's tenant domain");
    Assert.assertEquals(authenticationInfo.getTenantId(), MultitenantConstants.SUPER_TENANT_ID,
            "Authenticated user's tenant ID from BasicAuthenticator is not matching with the "
                    + "original user's tenant ID");
}
 
Example #13
Source File: WebappAuthenticationValveTest.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
/**
 * To create a request with the given authorization header
 *
 * @param authorizationHeader Authorization header
 * @return the relevant request.
 * @throws IllegalAccessException Illegal Access Exception.
 * @throws NoSuchFieldException   No Such Field Exception.
 */
private Request createRequest(String authorizationHeader) throws IllegalAccessException, NoSuchFieldException {
    Request request = new TestRequest("", "");
    Context context = new StandardContext();
    context.addParameter("basicAuth", "true");
    context.addParameter("managed-api-enabled", "true");
    context.setPath("carbon1");
    context.addParameter("doAuthentication", String.valueOf(true));
    request.setContext(context);
    MimeHeaders mimeHeaders = new MimeHeaders();
    MessageBytes bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
    bytes.setString(authorizationHeader);
    Field headersField = org.apache.coyote.Request.class.getDeclaredField("headers");
    headersField.setAccessible(true);
    org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
    headersField.set(coyoteRequest, mimeHeaders);
    request.setCoyoteRequest(coyoteRequest);
    return request;
}
 
Example #14
Source File: TomcatService.java    From armeria with Apache License 2.0 6 votes vote down vote up
private static void convertHeaders(HttpHeaders headers, MimeHeaders cHeaders) {
    if (headers.isEmpty()) {
        return;
    }

    for (Entry<AsciiString, String> e : headers) {
        final AsciiString k = e.getKey();
        final String v = e.getValue();

        if (k.isEmpty() || k.byteAt(0) == ':') {
            continue;
        }

        final MessageBytes cValue = cHeaders.addValue(k.array(), k.arrayOffset(), k.length());
        final byte[] valueBytes = v.getBytes(StandardCharsets.US_ASCII);
        cValue.setBytes(valueBytes, 0, valueBytes.length);
    }
}
 
Example #15
Source File: Response.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Special method for adding a session cookie as we should be overriding
 * any previous
 * @param cookie
 */
public void addSessionCookieInternal(final Cookie cookie) {
    if (isCommitted()) {
        return;
    }

    String name = cookie.getName();
    final String headername = "Set-Cookie";
    final String startsWith = name + "=";
    final StringBuffer sb = generateCookieString(cookie);
    boolean set = false;
    MimeHeaders headers = getCoyoteResponse().getMimeHeaders();
    int n = headers.size();
    for (int i = 0; i < n; i++) {
        if (headers.getName(i).toString().equals(headername)) {
            if (headers.getValue(i).toString().startsWith(startsWith)) {
                headers.getValue(i).setString(sb.toString());
                set = true;
            }
        }
    }
    if (!set) {
        addHeader(headername, sb.toString());
    }


}
 
Example #16
Source File: Response.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<String> getHeaderNames() {

    MimeHeaders headers = getCoyoteResponse().getMimeHeaders();
    int n = headers.size();
    List<String> result = new ArrayList<String>(n);
    for (int i = 0; i < n; i++) {
        result.add(headers.getName(i).toString());
    }
    return result;

}
 
Example #17
Source File: AbstractHttp11Processor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private boolean isConnectionClose(MimeHeaders headers) {
    MessageBytes connection = headers.getValue(Constants.CONNECTION);
    if (connection == null) {
        return false;
    }
    return connection.equals(Constants.CLOSE);
}
 
Example #18
Source File: AbstractHttp11Processor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private boolean isConnectionClose(MimeHeaders headers) {
    MessageBytes connection = headers.getValue(Constants.CONNECTION);
    if (connection == null) {
        return false;
    }
    return connection.equals(Constants.CLOSE);
}
 
Example #19
Source File: Response.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Special method for adding a session cookie as we should be overriding
 * any previous.
 *
 * @param cookie The new session cookie to add the response
 */
public void addSessionCookieInternal(final Cookie cookie) {
    if (isCommitted()) {
        return;
    }

    String name = cookie.getName();
    final String headername = "Set-Cookie";
    final String startsWith = name + "=";
    String header = generateCookieString(cookie);
    boolean set = false;
    MimeHeaders headers = getCoyoteResponse().getMimeHeaders();
    int n = headers.size();
    for (int i = 0; i < n; i++) {
        if (headers.getName(i).toString().equals(headername)) {
            if (headers.getValue(i).toString().startsWith(startsWith)) {
                headers.getValue(i).setString(header);
                set = true;
            }
        }
    }
    if (!set) {
        addHeader(headername, header);
    }


}
 
Example #20
Source File: Response.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Special method for adding a session cookie as we should be overriding
 * any previous
 * @param cookie
 */
public void addSessionCookieInternal(final Cookie cookie) {
    if (isCommitted()) {
        return;
    }

    String name = cookie.getName();
    final String headername = "Set-Cookie";
    final String startsWith = name + "=";
    final StringBuffer sb = generateCookieString(cookie);
    boolean set = false;
    MimeHeaders headers = getCoyoteResponse().getMimeHeaders();
    int n = headers.size();
    for (int i = 0; i < n; i++) {
        if (headers.getName(i).toString().equals(headername)) {
            if (headers.getValue(i).toString().startsWith(startsWith)) {
                headers.getValue(i).setString(sb.toString());
                set = true;
            }
        }
    }
    if (!set) {
        addHeader(headername, sb.toString());
    }


}
 
Example #21
Source File: JWTAuthenticatorTest.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
@Test(description = "This method tests the canHandle method under different conditions of request")
public void testHandle() throws IllegalAccessException, NoSuchFieldException {
    Request request = new Request();
    org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
    request.setCoyoteRequest(coyoteRequest);
    Assert.assertFalse(jwtAuthenticator.canHandle(request));
    MimeHeaders mimeHeaders = new MimeHeaders();
    MessageBytes bytes = mimeHeaders.addValue(JWT_HEADER);
    bytes.setString("test");
    headersField.set(coyoteRequest, mimeHeaders);
    request.setCoyoteRequest(coyoteRequest);
    Assert.assertTrue(jwtAuthenticator.canHandle(request));
}
 
Example #22
Source File: OauthAuthenticatorTest.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
/**
 * This will create an OAuth request.
 *
 * @param authorizationHeader Authorization Header
 */
private Request createOauthRequest(String authorizationHeader) throws IllegalAccessException {
    Request request = new Request();
    org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
    MimeHeaders mimeHeaders = new MimeHeaders();
    MessageBytes bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
    bytes.setString(authorizationHeader);
    headersField.set(coyoteRequest, mimeHeaders);
    request.setCoyoteRequest(coyoteRequest);
    return request;
}
 
Example #23
Source File: BasicAuthAuthenticatorTest.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
@Test(description = "This method tests the canHandle method when all the required parameters are given with the "
        + "request", dependsOnMethods = {"testCanHandleWithoutRequireParameters"})
public void testCanHandleWithRequireParameters() throws IllegalAccessException {
    request = new Request();
    context = new StandardContext();
    context.addParameter("basicAuth", "true");
    request.setContext(context);
    mimeHeaders = new MimeHeaders();
    bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
    bytes.setString(BASIC_HEADER);
    headersField.set(coyoteRequest, mimeHeaders);
    request.setCoyoteRequest(coyoteRequest);
    Assert.assertTrue(basicAuthAuthenticator.canHandle(request),
            "Basic Authenticator cannot handle a request with all the required headers and parameters.");
}
 
Example #24
Source File: CertificateAuthenticatorTest.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
/**
 * To create a request that can be understandable by Certificate Authenticator.
 *
 * @param headerName Name of the header
 * @param value      Value for the header
 * @return Request that is created.
 * @throws IllegalAccessException Illegal Access Exception.
 * @throws NoSuchFieldException   No Such Field Exception.
 */
private Request createRequest(String headerName, String value) throws IllegalAccessException, NoSuchFieldException {
    Request request = new Request();
    Context context = new StandardContext();
    request.setContext(context);
    org.apache.coyote.Request coyoteRequest = new org.apache.coyote.Request();
    MimeHeaders mimeHeaders = new MimeHeaders();
    MessageBytes bytes = mimeHeaders.addValue(headerName);
    bytes.setString(value);
    headersField.set(coyoteRequest, mimeHeaders);

    request.setCoyoteRequest(coyoteRequest);
    return request;
}
 
Example #25
Source File: TomcatService.java    From armeria with Apache License 2.0 5 votes vote down vote up
private static ResponseHeaders convertResponse(Response coyoteRes) {
    final ResponseHeadersBuilder headers = ResponseHeaders.builder();
    headers.status(coyoteRes.getStatus());

    final String contentType = coyoteRes.getContentType();
    if (contentType != null && !contentType.isEmpty()) {
        headers.set(HttpHeaderNames.CONTENT_TYPE, contentType);
    }

    final long contentLength = coyoteRes.getBytesWritten(true); // 'true' will trigger flush.
    final String method = coyoteRes.getRequest().method().toString();
    if (!"HEAD".equals(method)) {
        headers.setLong(HttpHeaderNames.CONTENT_LENGTH, contentLength);
    }

    final MimeHeaders cHeaders = coyoteRes.getMimeHeaders();
    final int numHeaders = cHeaders.size();
    for (int i = 0; i < numHeaders; i++) {
        final AsciiString name = toHeaderName(cHeaders.getName(i));
        if (name == null) {
            continue;
        }

        final String value = toHeaderValue(cHeaders.getValue(i));
        if (value == null) {
            continue;
        }

        headers.add(name.toLowerCase(), value);
    }

    return headers.build();
}
 
Example #26
Source File: Response.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public Collection<String> getHeaderNames() {
    MimeHeaders headers = getCoyoteResponse().getMimeHeaders();
    int n = headers.size();
    List<String> result = new ArrayList<>(n);
    for (int i = 0; i < n; i++) {
        result.add(headers.getName(i).toString());
    }
    return result;

}
 
Example #27
Source File: HeadersAdaptersTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Parameterized.Parameters(name = "headers [{0}]")
public static Object[][] arguments() {
	return new Object[][] {
			{CollectionUtils.toMultiValueMap(
					new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH))},
			{new NettyHeadersAdapter(new DefaultHttpHeaders())},
			{new TomcatHeadersAdapter(new MimeHeaders())},
			{new UndertowHeadersAdapter(new HeaderMap())},
			{new JettyHeadersAdapter(new HttpFields())}
	};
}
 
Example #28
Source File: Http2UpgradeHandler.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
void writeHeaders(Stream stream, int pushedStreamId, MimeHeaders mimeHeaders,
        boolean endOfStream, int payloadSize) throws IOException {
    // This ensures the Stream processing thread has control of the socket.
    synchronized (socketWrapper) {
        doWriteHeaders(stream, pushedStreamId, mimeHeaders, endOfStream, payloadSize);
    }
    stream.sentHeaders();
    if (endOfStream) {
        stream.sentEndOfStream();
    }
}
 
Example #29
Source File: HeadersAdaptersTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Parameterized.Parameters(name = "headers [{0}]")
public static Object[][] arguments() {
	return new Object[][] {
			{CollectionUtils.toMultiValueMap(
					new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH))},
			{new NettyHeadersAdapter(new DefaultHttpHeaders())},
			{new TomcatHeadersAdapter(new MimeHeaders())},
			{new UndertowHeadersAdapter(new HeaderMap())},
			{new JettyHeadersAdapter(new HttpFields())}
	};
}
 
Example #30
Source File: Http11Processor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private static boolean isConnectionToken(MimeHeaders headers, String token) throws IOException {
    MessageBytes connection = headers.getValue(Constants.CONNECTION);
    if (connection == null) {
        return false;
    }

    Set<String> tokens = new HashSet<>();
    TokenList.parseTokenList(headers.values(Constants.CONNECTION), tokens);
    return tokens.contains(token);
}