From a69a37f2b7afc4b09c1039c3548be776fd5b4ac7 Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Mon, 23 Sep 2024 10:09:07 -0600 Subject: [PATCH] Cleanup response header handling --- src/HTTP2.jl | 8 +------- src/client.jl | 9 ++++----- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/HTTP2.jl b/src/HTTP2.jl index 6a98389..3b0744a 100644 --- a/src/HTTP2.jl +++ b/src/HTTP2.jl @@ -235,11 +235,6 @@ function getclient(key::Tuple{SubString{String}, SubString{String}, UInt32, Bool end end -struct Header2 - name::String - value::String -end - mutable struct RequestContext client::Client retry_token::Ptr{aws_retry_token} @@ -250,7 +245,6 @@ mutable struct RequestContext request_body::Any body_byte_cursor::aws_byte_cursor response::Response - response_headers::Memory{Header2} temp_response_body::Any gzip_decompressing::Bool error_response_body::Union{Nothing, Vector{UInt8}} @@ -265,7 +259,7 @@ mutable struct RequestContext end function RequestContext(client, request, response, args...) - return RequestContext(client, C_NULL, false, Threads.Event(), nothing, request, nothing, aws_byte_cursor(0, C_NULL), response, Memory{Header2}(undef, 0), nothing, false, nothing, Ref{aws_http_make_request_options}(), C_NULL, C_NULL, args...) + return RequestContext(client, C_NULL, false, Threads.Event(), nothing, request, nothing, aws_byte_cursor(0, C_NULL), response, nothing, false, nothing, Ref{aws_http_make_request_options}(), C_NULL, C_NULL, args...) end struct StatusError <: Exception diff --git a/src/client.jl b/src/client.jl index 675609b..be573d9 100644 --- a/src/client.jl +++ b/src/client.jl @@ -192,11 +192,11 @@ const on_response_headers = Ref{Ptr{Cvoid}}(C_NULL) function c_on_response_headers(stream, header_block, header_array::Ptr{aws_http_header}, num_headers, ctx_ptr) ctx = unsafe_pointer_to_objref(ctx_ptr) - headers = ctx.response_headers + headers = ctx.response.headers oldlen = length(headers) newlen = oldlen + Int(num_headers) - newheaders = Memory{Header2}(undef, newlen) - ctx.response_headers = newheaders + newheaders = Vector{Header}(undef, newlen) + ctx.response.headers = newheaders for i = 1:oldlen newheaders[i] = headers[i] end @@ -204,7 +204,7 @@ function c_on_response_headers(stream, header_block, header_array::Ptr{aws_http_ header = unsafe_load(header_array, i) name = unsafe_string(header.name.ptr, header.name.len) value = unsafe_string(header.value.ptr, header.value.len) - newheaders[oldlen + i] = Header2(name, value) + newheaders[oldlen + i] = name => value end return Cint(0) end @@ -216,7 +216,6 @@ const on_response_header_block_done = Ref{Ptr{Cvoid}}(C_NULL) function c_on_response_header_block_done(stream, header_block, ctx_ptr) ctx = unsafe_pointer_to_objref(ctx_ptr) ref = Ref{Cint}() - ctx.response.headers = [x.name => x.value for x in ctx.response_headers] aws_http_stream_get_incoming_response_status(stream, ref) ctx.response.status = ref[] if ctx.status_exception && ctx.response.status >= 299