Skip to content

Commit

Permalink
Cleanup response header handling
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Sep 23, 2024
1 parent ec8876a commit a69a37f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
8 changes: 1 addition & 7 deletions src/HTTP2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}}
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions src/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,19 @@ 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
for i = 1:num_headers
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
Expand All @@ -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
Expand Down

0 comments on commit a69a37f

Please sign in to comment.