Skip to content

Commit 8b690aa

Browse files
committed
Get more server tests working
1 parent eae8ed9 commit 8b690aa

File tree

6 files changed

+238
-94
lines changed

6 files changed

+238
-94
lines changed

src/HTTP.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module HTTP
33
using CodecZlib, URIs, Mmap, Base64
44
using LibAwsCommon, LibAwsIO, LibAwsHTTP
55

6+
export @logfmt_str, common_logfmt, combined_logfmt
67
export WebSockets
78

89
include("utils.jl")

src/access_log.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ function symbol_mapping(s::Symbol)
5959
str = string(s)
6060
if (m = match(r"^http_(.+)$", str); m !== nothing)
6161
hdr = replace(String(m[1]), '_' => '-')
62-
:(HTTP.header(http.message, $hdr, "-"))
62+
:(something(HTTP.getheader(http.request.headers, $hdr), "-"))
6363
elseif (m = match(r"^sent_http_(.+)$", str); m !== nothing)
6464
hdr = replace(String(m[1]), '_' => '-')
65-
:(HTTP.header(http.message.response, $hdr, "-"))
65+
:(something(HTTP.getheader(http.response.headers, $hdr), "-"))
6666
elseif s === :remote_addr
67-
:(http.stream.peerip)
67+
:(HTTP.remote_address(http.connection))
6868
elseif s === :remote_port
69-
:(http.stream.peerport)
69+
:(HTTP.remote_port(http.connection))
7070
elseif s === :remote_user
7171
:("-") # TODO: find from Basic auth...
7272
elseif s === :time_iso8601
@@ -89,17 +89,17 @@ function symbol_mapping(s::Symbol)
8989
m = symbol_mapping(:request_method)
9090
t = symbol_mapping(:request_uri)
9191
p = symbol_mapping(:server_protocol)
92-
(m, " ", t, " ", p...)
92+
(m, " ", t, " ", p)
9393
elseif s === :request_method
94-
:(http.message.method)
94+
:(http.request.method)
9595
elseif s === :request_uri
96-
:(http.message.target)
96+
:(http.request.target)
9797
elseif s === :server_protocol
98-
("HTTP/", :(http.message.version.major), ".", :(http.message.version.minor))
98+
:(HTTP.http_version(http.connection))
9999
elseif s === :status
100-
:(http.message.response.status)
100+
:(http.response.status)
101101
elseif s === :body_bytes_sent
102-
return :(max(0, http.nwritten))
102+
:(HTTP.bodylen(http.response))
103103
else
104104
error("unknown variable in logfmt: $s")
105105
end

src/client/request.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function with_request(f::Function, client::Client, method, path, headers=nothing
2424
setheader(h, "host", client.settings.host)
2525
end
2626
setheaderifabsent(h, "accept", "*/*")
27-
setheaderifabsent(h, "user-agent", USER_AGENT[])
27+
setheaderifabsent(h, "user-agent", something(USER_AGENT[], "-"))
2828
if decompress === nothing || decompress
2929
setheaderifabsent(h, "accept-encoding", "gzip")
3030
end

src/requestresponse.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ function InputStream(allocator::Ptr{aws_allocator}, body::RequestBodyTypes)
141141
end
142142

143143
function setinputstream!(msg::Message, body)
144+
aws_http_message_set_body_stream(msg.ptr, C_NULL)
145+
msg.inputstream = nothing
146+
body === nothing && return
144147
input_stream = InputStream(msg.allocator, body)
145148
setfield!(msg, :inputstream, input_stream)
146149
if input_stream.ptr != C_NULL
@@ -158,7 +161,7 @@ end
158161
mutable struct Request <: Message
159162
allocator::Ptr{aws_allocator}
160163
ptr::Ptr{aws_http_message}
161-
inputstream::InputStream # used for outgoing request body
164+
inputstream::Union{Nothing, InputStream} # used for outgoing request body
162165
# only set in server-side request handlers
163166
body::Union{Nothing, Vector{UInt8}}
164167
route::Union{Nothing, String}
@@ -181,6 +184,7 @@ mutable struct Request <: Message
181184
end
182185
req = new(allocator, ptr)
183186
req.body = nothing
187+
req.inputstream = nothing
184188
req.route = nothing
185189
req.params = nothing
186190
req.cookies = nothing
@@ -291,7 +295,7 @@ RequestMetrics() = RequestMetrics(0, 0, 0, nothing)
291295
mutable struct Response <: Message
292296
allocator::Ptr{aws_allocator}
293297
ptr::Ptr{aws_http_message}
294-
inputstream::InputStream
298+
inputstream::Union{Nothing, InputStream}
295299
body::Union{Nothing, Vector{UInt8}} # only set for client-side response body when no user-provided response_body
296300
metrics::RequestMetrics
297301
request::Request
@@ -311,6 +315,7 @@ mutable struct Response <: Message
311315
end
312316
resp = new(allocator, ptr)
313317
resp.body = nothing
318+
resp.inputstream = nothing
314319
body !== nothing && setinputstream!(resp, body)
315320
return finalizer(_ -> aws_http_message_release(ptr), resp)
316321
catch
@@ -324,6 +329,8 @@ Response(body=nothing) = Response(0, nothing, body)
324329
Response(status::Integer, body) = Response(status, nothing, Vector{UInt8}(string(body)))
325330
Response(status::Integer) = Response(status, nothing, nothing)
326331

332+
bodylen(m::Message) = isdefined(m, :inputstream) && m.inputstream !== nothing ? m.inputstream.bodylen : 0
333+
327334
function Base.getproperty(x::Response, s::Symbol)
328335
if s == :status
329336
ref = Ref{Cint}()

0 commit comments

Comments
 (0)