Skip to content

Commit dba6c98

Browse files
authored
Skip body building when HTTP call body is absent (#1649)
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
1 parent 4170f92 commit dba6c98

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

‎impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/HttpExecutorBuilder.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ private RequestExecutor buildRequestExecutor() {
140140
case HttpMethod.POST:
141141
case HttpMethod.PUT:
142142
case HttpMethod.PATCH:
143-
return new WithBodyRequestExecutor(
144-
httpMethod, redirect, auth, definition.application(), body);
143+
return body != null
144+
? new WithBodyRequestExecutor(
145+
httpMethod, redirect, auth, definition.application(), body)
146+
: new WithoutBodyRequestExecutor(httpMethod, redirect, auth);
145147
case HttpMethod.DELETE:
146148
case HttpMethod.HEAD:
147149
case HttpMethod.OPTIONS:

‎impl/test/src/test/java/io/serverlessworkflow/impl/test/HTTPWorkflowDefinitionTest.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,27 @@ void callHttpPost_should_return_created_firstName() throws Exception {
324324
});
325325
}
326326

327+
@Test
328+
void callHttpPost_without_body_should_not_throw() throws Exception {
329+
mockServer.enqueue(new MockResponse(204, Headers.of(), ""));
330+
331+
assertDoesNotThrow(
332+
() ->
333+
appl.workflowDefinition(
334+
readWorkflowFromClasspath("workflows-samples/call-http-post-no-body.yaml"))
335+
.instance(Map.of())
336+
.start()
337+
.join());
338+
339+
RecordedRequest recordedRequest = mockServer.takeRequest();
340+
SoftAssertions.assertSoftly(
341+
softly -> {
342+
softly.assertThat(recordedRequest.getMethod()).isEqualTo("POST");
343+
softly.assertThat(recordedRequest.getUrl()).asString().contains("/api/v1/authors");
344+
softly.assertThat(recordedRequest.getBodySize()).isEqualTo(0);
345+
});
346+
}
347+
327348
@Test
328349
void testCallHttpDelete() throws IOException, InterruptedException {
329350
mockServer.enqueue(new MockResponse(204, Headers.of(), ""));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
document:
2+
dsl: 1.0.0-alpha1
3+
namespace: test
4+
name: call-http-post-no-body
5+
version: 1.0.0
6+
do:
7+
- postAuthors:
8+
call: http
9+
with:
10+
method: post
11+
endpoint:
12+
uri: http://localhost:9876/api/v1/authors

0 commit comments

Comments
 (0)