Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Jan 31, 2025
1 parent a84875e commit 2725fc5
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- ## [Unreleased] -->

## [v2.0.0] - 2025-02-01
### Changed


## [v1.10.1] - 2023-11-28
### Changed
- Server errors are no longer serialized back to the client since this might leak sensitive
Expand Down
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ LibAwsHTTP = "ce851869-0d7a-41e7-95ef-2d4cb63876dd"
LibAwsIO = "a5388770-19df-4151-b103-3d71de896ddf"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"

[compat]
JSON = "0.21.4"
PrecompileTools = "1.2.1"
julia = "1.10"

[extras]
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
NetworkOptions = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
Expand Down
14 changes: 13 additions & 1 deletion src/HTTP.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module HTTP

using CodecZlib, URIs, Mmap, Base64, Dates
using CodecZlib, URIs, Mmap, Base64, Dates, Sockets
using LibAwsCommon, LibAwsIO, LibAwsHTTP

export @logfmt_str, common_logfmt, combined_logfmt
Expand Down Expand Up @@ -97,4 +97,16 @@ function __init__()
return
end

# only run if precompiling
if VERSION >= v"1.9.0-0" && ccall(:jl_generating_output, Cint, ()) == 1
do_precompile = true
try
Sockets.getalladdrinfo("localhost")
catch ex
@debug "Skipping precompilation workload because localhost cannot be resolved. Check firewall settings" exception=(ex,catch_backtrace())
do_precompile = false
end
do_precompile && include("precompile.jl")
end

end
9 changes: 0 additions & 9 deletions src/client/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,17 @@ function c_on_response_body(aws_stream_ptr, data::Ptr{aws_byte_cursor}, stream_p
if stream.decompress
if stream.gzipstream === nothing
stream.bufferstream = b = Base.BufferStream()
Core.println("gzip BufferStream: len = $(length(b.buffer.data)), size = $(b.buffer.size)")
stream.gzipstream = g = CodecZlib.GzipDecompressorStream(b)
# @info "decompress 1" ptr=data len=bc.len
unsafe_write(g, bc.ptr, bc.len)
Core.println("gzip BufferStream after write: len = $(length(b.buffer.data)), size = $(b.buffer.size)")
else
# @info "decompress 2" ptr=data len=bc.len
unsafe_write(stream.gzipstream, bc.ptr, bc.len)
end
else
if stream.bufferstream === nothing
stream.bufferstream = b = Base.BufferStream()
Core.println("BufferStream: len = $(length(b.buffer.data)), size = $(b.buffer.size)")
# @info "writebuf 1" ptr=data len=bc.len
unsafe_write(b, bc.ptr, bc.len)
Core.println("BufferStream after write: len = $(length(b.buffer.data)), size = $(b.buffer.size)")
else
# @info "writebuf 2" ptr=data len=bc.len
unsafe_write(stream.bufferstream, bc.ptr, bc.len)
Core.println("after write: len = $(length(stream.bufferstream.buffer.data)), size = $(stream.bufferstream.buffer.size)")
end
end
return Cint(0)
Expand Down
1 change: 0 additions & 1 deletion src/forms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export Form, Multipart, content_type, parse_multipart_form

import ..sniff


# Form request body
mutable struct Form <: IO
data::Vector{IO}
Expand Down
38 changes: 14 additions & 24 deletions src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,32 @@ using PrecompileTools: @setup_workload, @compile_workload

try
@setup_workload begin
# These need to be safe to call here and bake into the pkgimage, i.e. called twice.
Connections.__init__()
MultiPartParsing.__init__()
Parsers.__init__()

# Doesn't seem to be needed here, and might not be safe to call twice (here and during runtime)
# ConnectionRequest.__init__()

HTTP.__init__()
@info "HTTP initialized"
gzip_data(data::String) = read(GzipCompressorStream(IOBuffer(data)))

# random port in the dynamic/private range (49152–65535) which are are
# least likely to be used by well-known services
_port = 57813

cert, key = joinpath.(@__DIR__, "../test", "resources", ("cert.pem", "key.pem"))
sslconfig = MbedTLS.SSLConfig(cert, key)

server = HTTP.serve!("0.0.0.0", _port; verbose = -1, listenany=true, sslconfig=sslconfig) do req
server = HTTP.serve!("0.0.0.0", _port; listenany=true) do req
HTTP.Response(200, ["Content-Encoding" => "gzip"], gzip_data("dummy response"))
end
# listenany allows changing port if that one is already in use, so check the actual port
_port = HTTP.port(server)
url = "http://localhost:$_port"
env = ["JULIA_NO_VERIFY_HOSTS" => "localhost",
"JULIA_SSL_NO_VERIFY_HOSTS" => nothing,
"JULIA_ALWAYS_VERIFY_HOSTS" => nothing]
@info "HTTP server started on port $_port"
try
# listenany allows changing port if that one is already in use, so check the actual port
_port = HTTP.port(server)
url = "https://localhost:$_port"

env = ["JULIA_NO_VERIFY_HOSTS" => "localhost",
"JULIA_SSL_NO_VERIFY_HOSTS" => nothing,
"JULIA_ALWAYS_VERIFY_HOSTS" => nothing]

withenv(env...) do
@compile_workload begin
HTTP.get(url);
@show HTTP.get(url)
end
end
finally
HTTP.forceclose(server)
@info "Shutting down HTTP server"
close(server)
@info "HTTP server shut down"
yield() # needed on 1.9 to avoid some issue where it seems a task doesn't stop before serialization
server = nothing
end
Expand Down
1 change: 0 additions & 1 deletion src/requestresponse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -411,5 +411,4 @@ Does this `Response` have a redirect status?
isredirect(r::Response) = isredirect(r.status)
isredirect(status::Integer) = status in (301, 302, 303, 307, 308)


Forms.parse_multipart_form(m::Message) = parse_multipart_form(getheader(m.headers, "content-type"), m.body)
5 changes: 4 additions & 1 deletion src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ function serve!(f, host="127.0.0.1", port=8080;
initial_window_size=typemax(UInt64),
)
if listenany
@warn "listenany not yet supported; only trying port = $port"
port, sock = Sockets.listenany(port)
# don't need the socket server, so immediately close
# (we were just looking for an open port)
close(sock)
end
server = Server{typeof(f)}(
f, # RequestHandler
Expand Down

0 comments on commit 2725fc5

Please sign in to comment.