static int s_stream_on_incoming_headers()

in native/src/http_client.c [119:148]


static int s_stream_on_incoming_headers(
    struct aws_http_stream *s,
    enum aws_http_header_block header_block,
    const struct aws_http_header *headers,
    size_t header_count,
    void *user_data) {
    (void)s;

    struct aws_dotnet_http_stream *stream = user_data;
    struct aws_allocator *allocator = aws_dotnet_get_allocator();
    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) {
        header_strings[header_idx] =
            aws_string_new_from_array(allocator, headers[header_idx].name.ptr, headers[header_idx].name.len);
        header_strings[header_idx + 1] =
            aws_string_new_from_array(allocator, headers[header_idx].value.ptr, headers[header_idx].value.len);
        dotnet_headers[header_idx].name = (const char *)header_strings[header_idx]->bytes;
        dotnet_headers[header_idx].value = (const char *)header_strings[header_idx + 1]->bytes;
    }

    int status = 0;
    aws_http_stream_get_incoming_response_status(stream->stream, &status);
    stream->on_incoming_headers(status, header_block, dotnet_headers, (uint32_t)header_count);
    for (size_t idx = 0; idx < header_count * 2; ++idx) {
        aws_string_destroy(header_strings[idx]);
    }

    return AWS_OP_SUCCESS;
}