Skip to content

Commit

Permalink
fix invoke HEAD method failure (#952)
Browse files Browse the repository at this point in the history
* fix invoke HEAD method failure

Signed-off-by: MregXN <[email protected]>

* add unit test

Signed-off-by: MregXN <[email protected]>

* remove unused package

Signed-off-by: MregXN <[email protected]>

---------

Signed-off-by: MregXN <[email protected]>
Co-authored-by: Artur Souza <[email protected]>
  • Loading branch information
MregXN and artursouza authored Nov 27, 2023
1 parent e4cb03f commit c91c410
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sdk/src/main/java/io/dapr/client/DaprHttp.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ private CompletableFuture<Response> doInvokeApi(String method,
requestBuilder.get();
} else if (HttpMethods.DELETE.name().equals(method)) {
requestBuilder.delete();
} else if (HttpMethods.HEAD.name().equals(method)) {
requestBuilder.head();
} else {
requestBuilder.method(method, body);
}
Expand Down
12 changes: 11 additions & 1 deletion sdk/src/test/java/io/dapr/client/DaprHttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

@ExtendWith(SystemStubsExtension.class)
Expand Down Expand Up @@ -138,6 +138,16 @@ public void invokeDeleteMethod() throws IOException {
assertEquals(EXPECTED_RESULT, body);
}

@Test
public void invokeHEADMethod() throws IOException {
mockInterceptor.addRule().head("http://127.0.0.1:3500/v1.0/state").respond(HttpURLConnection.HTTP_OK);
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
Mono<DaprHttp.Response> mono =
daprHttp.invokeApi("HEAD", "v1.0/state".split("/"), null, (String) null, null, Context.empty());
DaprHttp.Response response = mono.block();
assertEquals(HttpURLConnection.HTTP_OK, response.getStatusCode());
}

@Test
public void invokeGetMethod() throws IOException {
mockInterceptor.addRule()
Expand Down

0 comments on commit c91c410

Please sign in to comment.