static void s_complete_http_request_signing_normally()

in native/src/signing.c [176:226]


static void s_complete_http_request_signing_normally(
    struct aws_dotnet_signing_callback_state *callback_state,
    struct aws_string *signature) {
    struct aws_allocator *allocator = aws_dotnet_get_allocator();

    struct aws_byte_cursor path_cursor;
    AWS_ZERO_STRUCT(path_cursor);

    aws_http_message_get_request_path(callback_state->request, &path_cursor);
    struct aws_string *uri = aws_string_new_from_cursor(allocator, &path_cursor);

    size_t header_count = aws_http_message_get_header_count(callback_state->request);
    AWS_VARIABLE_LENGTH_ARRAY(struct aws_dotnet_http_header, dotnet_headers, header_count);
    AWS_VARIABLE_LENGTH_ARRAY(struct aws_string *, header_strings, header_count * 2);

    for (size_t header_idx = 0; header_idx < header_count; ++header_idx) {
        size_t string_index = header_idx * 2;
        header_strings[string_index] = NULL;
        header_strings[string_index + 1] = NULL;

        AWS_ZERO_STRUCT(dotnet_headers[header_idx]);

        struct aws_http_header header;
        AWS_ZERO_STRUCT(header);

        if (aws_http_message_get_header(callback_state->request, &header, header_idx)) {
            continue;
        }

        header_strings[string_index] = aws_string_new_from_array(allocator, header.name.ptr, header.name.len);
        header_strings[string_index + 1] = aws_string_new_from_array(allocator, header.value.ptr, header.value.len);

        dotnet_headers[header_idx].name = (const char *)header_strings[string_index]->bytes;
        dotnet_headers[header_idx].value = (const char *)header_strings[string_index + 1]->bytes;
    }

    callback_state->on_signing_complete(
        callback_state->callback_id,
        AWS_ERROR_SUCCESS,
        signature->bytes,
        signature->len,
        (const char *)uri->bytes,
        dotnet_headers,
        (uint32_t)header_count);

    aws_string_destroy(uri);

    for (size_t idx = 0; idx < header_count * 2; ++idx) {
        aws_string_destroy(header_strings[idx]);
    }
}