@SuppressWarnings("unchecked")
    public Output run(RunContext runContext) throws Exception {
        Logger logger = runContext.logger();

        try (HttpClient client = this.client(runContext, this.method)) {
            HttpRequest<String> request = this.request(runContext);
            HttpResponse<String> response;

            try {
                response = client
                    .toBlocking()
                    .exchange(request, Argument.STRING, Argument.STRING);

                // check that the string is a valid Unicode string
                if (response.getBody().isPresent()) {
                    OptionalInt illegalChar = response.body().chars().filter(c -> !Character.isDefined(c)).findFirst();
                    if (illegalChar.isPresent()) {
                        throw new IllegalArgumentException("Illegal unicode code point in request body: " + illegalChar.getAsInt() +
                            ", the Request task only support valid Unicode strings as body.\n" +
                            "You can try using the Download task instead.");
                    }
                }
            } catch (HttpClientResponseException e) {
                if (!allowFailed) {
                    throw e;
                }

                //noinspection unchecked
                response = (HttpResponse<String>) e.getResponse();
            }

            logger.debug("Request '{}' with the response code '{}'", request.getUri(), response.getStatus().getCode());

            return this.output(runContext, request, response);
        }
    }
@Test
    void head() throws Exception {
        final String url = "https://sampletestfile.com/wp-content/uploads/2023/07/500KB-CSV.csv";

        Request task = Request.builder()
            .id(RequestTest.class.getSimpleName())
            .type(RequestTest.class.getName())
            .uri(url)
            .method(HttpMethod.HEAD)
            .build();

        RunContext runContext = TestsUtils.mockRunContext(this.runContextFactory, task, ImmutableMap.of());

        Request.Output output = task.run(runContext);

        assertThat(output.getUri(), is(URI.create(url)));
        assertThat(output.getHeaders().get("content-length").getFirst(), is("512789"));
    }