Skip to content

Commit 16e1877

Browse files
committed
minimalist test and remove the write data level check for http
1 parent 52e2841 commit 16e1877

3 files changed

Lines changed: 11 additions & 71 deletions

File tree

src/main/java/software/amazon/awssdk/crt/http/HttpClientConnection.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ public HttpStream makeRequest(HttpRequest request, HttpStreamResponseHandler str
8888
new HttpStreamResponseHandlerNativeAdapter(streamHandler),
8989
useManualDataWrites);
9090

91-
HttpStream h1Stream = (HttpStream)stream;
92-
h1Stream.setHasBodyStream(request.getBodyStream() != null);
93-
return h1Stream;
91+
return (HttpStream)stream;
9492
}
9593

9694
/**

src/main/java/software/amazon/awssdk/crt/http/HttpStream.java

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@
1616
*/
1717
public class HttpStream extends HttpStreamBase {
1818

19-
/**
20-
* Tracks whether this stream was created with a body stream on the request.
21-
* Used to guard against calling {@link #writeData} on a stream that already
22-
* has a body stream — HTTP/1.1 requires exactly one body framing mechanism
23-
* per message, so a body stream and manual writes cannot coexist. See
24-
* {@link HttpClientConnection#makeRequest(HttpRequest, HttpStreamResponseHandler, boolean)}
25-
* for details.
26-
*/
27-
private boolean hasBodyStream = false;
28-
2919
/*
3020
* Native code will call this constructor during
3121
* HttpClientConnection.makeRequest()
@@ -34,34 +24,6 @@ protected HttpStream(long ptr) {
3424
super(ptr);
3525
}
3626

37-
/**
38-
* Package-private. Called by HttpClientConnection.makeRequest() to record
39-
* whether the originating request had a body stream attached.
40-
*/
41-
void setHasBodyStream(boolean hasBodyStream) {
42-
this.hasBodyStream = hasBodyStream;
43-
}
44-
45-
/**
46-
* {@inheritDoc}
47-
*
48-
* <p>This method supersedes the deprecated {@link #writeChunk} methods.
49-
* Calls the base {@code writeData} method after verifying that the stream
50-
* was not created with a body stream.
51-
*/
52-
@Override
53-
public void writeData(final byte[] data, boolean endStream,
54-
final HttpStreamWriteDataCompletionCallback completionCallback) {
55-
if (hasBodyStream) {
56-
throw new IllegalStateException(
57-
"Cannot call writeData() on an HTTP/1.1 stream that was created with a body stream. "
58-
+ "HTTP/1.1 requires exactly one body framing mechanism per message (RFC 9112, Section 6). "
59-
+ "A body stream and manual writeData() calls cannot coexist. "
60-
+ "Create the stream with useManualDataWrites=true and no body stream to use writeData().");
61-
}
62-
super.writeData(data, endStream, completionCallback);
63-
}
64-
6527
/**
6628
* Completion interface for writing chunks to an http stream
6729
*/

src/test/java/software/amazon/awssdk/crt/test/WriteDataTest.java

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public void onResponseComplete(HttpStreamBase stream, int errorCode) {
284284
* Tests that makeRequest throws IllegalStateException when called with both
285285
* a body stream and useManualDataWrites=true on an HTTP/1.1 connection.
286286
*/
287-
@Test(expected = IllegalStateException.class)
287+
@Test
288288
public void testHttp1MakeRequestWithBodyStreamAndManualWrites() throws Exception {
289289
skipIfAndroid();
290290
skipIfLocalhostUnavailable();
@@ -304,46 +304,26 @@ public boolean sendRequestBody(ByteBuffer bodyBytesOut) {
304304
// Create request WITH body stream AND useManualDataWrites=true
305305
HttpRequest request = new HttpRequest("PUT", "/echo", headers, bodyStream);
306306

307-
CompletableFuture<Void> reqCompleted = new CompletableFuture<>();
308-
TestHttpResponse response = new TestHttpResponse();
309-
310-
CompletableFuture<Void> shutdownComplete;
311307
try (HttpClientConnectionManager connPool = createConnectionPoolManager(uri, HttpVersion.HTTP_1_1)) {
312-
shutdownComplete = connPool.getShutdownCompleteFuture();
313308
try (HttpClientConnection conn = connPool.acquireConnection().get(60, TimeUnit.SECONDS)) {
314309

315310
HttpStreamResponseHandler streamHandler = new HttpStreamResponseHandler() {
316311
@Override
317312
public void onResponseHeaders(HttpStream stream, int responseStatusCode, int blockType,
318-
HttpHeader[] nextHeaders) {
319-
response.statusCode = responseStatusCode;
320-
response.headers.addAll(Arrays.asList(nextHeaders));
321-
}
322-
313+
HttpHeader[] nextHeaders) {}
323314
@Override
324-
public int onResponseBody(HttpStream stream, byte[] bodyBytesIn) {
325-
response.bodyBuffer.put(bodyBytesIn);
326-
return bodyBytesIn.length;
327-
}
328-
315+
public int onResponseBody(HttpStream stream, byte[] bodyBytesIn) { return bodyBytesIn.length; }
329316
@Override
330-
public void onResponseComplete(HttpStream stream, int errorCode) {
331-
response.onCompleteErrorCode = errorCode;
332-
reqCompleted.complete(null);
333-
}
317+
public void onResponseComplete(HttpStream stream, int errorCode) {}
334318
};
335319

336-
HttpStream stream = conn.makeRequest(request, streamHandler, true);
337-
stream.activate();
338-
339-
stream.writeData("hello".getBytes(StandardCharsets.UTF_8), true, null);
340-
341-
reqCompleted.get(60, TimeUnit.SECONDS);
342-
stream.close();
320+
try {
321+
conn.makeRequest(request, streamHandler, true);
322+
Assert.fail("Expected IllegalStateException from makeRequest");
323+
} catch (IllegalStateException e) {
324+
Assert.assertTrue(e.getMessage().contains("manual data writes"));
325+
}
343326
}
344327
}
345-
346-
shutdownComplete.get(60, TimeUnit.SECONDS);
347-
CrtResource.waitForNoResources();
348328
}
349329
}

0 commit comments

Comments
 (0)