Skip to content

[4.x] 6121 100 continue request reset fix #6251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2023
Merged
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 @@ -534,6 +534,7 @@ public SocketHttpClient manualRequest(String formatString, Object... args) throw

/**
* Continue sending more to text to socket.
*
* @param payload text to be sent
* @return this http client
* @throws IOException
Expand All @@ -548,6 +549,18 @@ public SocketHttpClient continuePayload(String payload)
return this;
}

/**
* Send single chunk as defined by RFC 9112 §7.1.
*
* @param payload of the chunk
* @return this http client
* @throws IOException
*/
public SocketHttpClient sendChunk(String payload) throws IOException {
continuePayload(Integer.toHexString(payload.length()) + EOL + payload + EOL);
return this;
}

/**
* Override this to send a specific payload.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
import io.helidon.nima.webserver.http.Handler;
import io.helidon.nima.webserver.http.HttpRouting;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.time.Duration;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -90,6 +94,13 @@ static void routing(HttpRouting.Builder router) {
)
.route(Http.Method.predicate(Http.Method.PUT, Http.Method.POST),
PathMatchers.exact("/"), anyHandler)
.route(Http.Method.predicate(Http.Method.PUT),
PathMatchers.exact("/chunked"), (req, res) -> {
try (InputStream is = req.content().inputStream();
OutputStream os = res.outputStream()) {
new ByteArrayInputStream(is.readAllBytes()).transferTo(os);
}
})
.route(Http.Method.predicate(Http.Method.GET),
PathMatchers.exact("/"), (req, res) -> res.status(Http.Status.OK_200).send("GET TEST"));
}
Expand All @@ -98,6 +109,32 @@ public Continue100Test(WebServer server) {
defaultPort = server.port();
}

@Test
void continue100ChunkedPut() throws Exception {
try (SocketHttpClient socketHttpClient = SocketHttpClient.create(defaultPort)) {
socketHttpClient
.manualRequest("""
PUT /chunked HTTP/1.1
Host: localhost:%d
Expect: 100-continue
Accept: */*
Transfer-Encoding: chunked
Content-Type: text/plain

""", defaultPort)
.awaitResponse("HTTP/1.1 100 Continue", "\n\n")
.sendChunk("This ")
.sendChunk("is ")
.sendChunk("chunked!")
.sendChunk("");

String received = socketHttpClient.receive();
assertThat(received, startsWith("HTTP/1.1 200 OK"));
assertThat(received, endsWith("This is chunked!"));

checkKeepAlive(socketHttpClient);
}
}
@Test
void continue100Post() throws Exception {
try (SocketHttpClient socketHttpClient = SocketHttpClient.create(defaultPort)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ public OutputStream outputStream() {
}
streamingEntity = true;

request.reset();

this.outputStream = new BlockingOutputStream(headers,
trailers,
this::status,
Expand All @@ -162,6 +160,7 @@ public OutputStream outputStream() {
() -> {
this.isSent = true;
afterSend();
request.reset();
},
ctx,
sendListener,
Expand Down