Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ public void consumeHeader(final List<Header> headers, final boolean endStream) t
if (status < HttpStatus.SC_INFORMATIONAL) {
throw new ProtocolException("Invalid response: " + new StatusLine(response));
}
if (status < HttpStatus.SC_SUCCESS && endStream) {
throw new ProtocolException("Informational response must not set END_STREAM");
}
if (status > HttpStatus.SC_CONTINUE && status < HttpStatus.SC_SUCCESS) {
exchangeHandler.consumeInformation(response, context);
}
Expand Down Expand Up @@ -238,6 +241,9 @@ public void consumeHeader(final List<Header> headers, final boolean endStream) t
responseState.set(endStream ? MessageState.COMPLETE : MessageState.BODY);
break;
case BODY:
if (!endStream) {
throw new ProtocolException("Trailer headers must set END_STREAM");
}
TrailersValidationSupport.verify(headers);
responseState.set(MessageState.COMPLETE);
exchangeHandler.streamEnd(headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
*/
package org.apache.hc.core5.http2.impl.nio;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.ProtocolException;
import org.apache.hc.core5.http.impl.BasicHttpConnectionMetrics;
import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
Expand Down Expand Up @@ -117,6 +119,24 @@ void consumeTrailersWithPseudoHeaderRejected() throws Exception {
Mockito.verify(exchangeHandler, Mockito.never()).streamEnd(Mockito.anyList());
}

@Test
void informationalResponseWithEndStreamRejected() throws HttpException, IOException {
final List<Header> responseHeaders = Collections.singletonList(
new BasicHeader(":status", "103"));
Assertions.assertThrows(ProtocolException.class, () -> handler.consumeHeader(responseHeaders, true));
Mockito.verify(exchangeHandler, Mockito.never()).consumeInformation(Mockito.any(), Mockito.any());
}
@Test
void consumeTrailersWithoutEndStreamRejected() throws Exception {
final List<Header> responseHeaders = Collections.singletonList(
new BasicHeader(":status", "200"));
handler.consumeHeader(responseHeaders, false);

final List<Header> trailers = Collections.singletonList(
new BasicHeader("x-checksum", "abc123"));
Assertions.assertThrows(ProtocolException.class, () -> handler.consumeHeader(trailers, false));
Mockito.verify(exchangeHandler, Mockito.never()).streamEnd(Mockito.anyList());
}
@Test
void contentLengthValid() throws Exception {
final List<Header> responseHeaders = Arrays.asList(
Expand Down
Loading