Skip to content

Commit

Permalink
Remove usage of deprecated verbosity macros (#1190)
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj authored Oct 28, 2024
1 parent 4ebb277 commit c031311
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 71 deletions.
18 changes: 9 additions & 9 deletions src/Connections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Connections

export Connection, newconnection, releaseconnection, getrawstream, inactiveseconds, shouldtimeout, default_connection_limit, set_default_connection_limit!, Pool

using Sockets, LoggingExtras, NetworkOptions
using Sockets, NetworkOptions
using MbedTLS: SSLConfig, SSLContext, setup!, associate!, hostname!, handshake!
using MbedTLS, OpenSSL, ConcurrentUtilities
using ..IOExtras, ..Conditions, ..Exceptions
Expand Down Expand Up @@ -254,7 +254,7 @@ end
function IOExtras.startwrite(c::Connection)
@require !iswritable(c)
c.writable = true
@debugv 3 "👁 Start write:$c"
@debug "👁 Start write:$c"
return
end

Expand All @@ -266,7 +266,7 @@ Signal that an entire Request Message has been written to the `Connection`.
function IOExtras.closewrite(c::Connection)
@require iswritable(c)
c.writable = false
@debugv 3 "🗣 Write done: $c"
@debug "🗣 Write done: $c"
flush(c)
return
end
Expand All @@ -278,7 +278,7 @@ function IOExtras.startread(c::Connection)
@require !isreadable(c)
c.timestamp = time()
c.readable = true
@debugv 3 "👁 Start read: $c"
@debug "👁 Start read: $c"
return
end

Expand All @@ -289,7 +289,7 @@ TODO: or if response data arrives when no request was sent (isreadable == false)
"""
function monitor_idle_connection(c::Connection)
try
if eof(c.io) ;@debugv 3 "💀 Closed: $c"
if eof(c.io) ;@debug "💀 Closed: $c"
close(c.io)
end
catch ex
Expand All @@ -307,7 +307,7 @@ Signal that an entire Response Message has been read from the `Connection`.
function IOExtras.closeread(c::Connection)
@require isreadable(c)
c.readable = false
@debugv 3 "✉️ Read done: $c"
@debug "✉️ Read done: $c"
if c.clientconnection
t = Threads.@spawn monitor_idle_connection(c)
@isdefined(errormonitor) && errormonitor(t)
Expand Down Expand Up @@ -516,7 +516,7 @@ function getconnection(::Type{TCPSocket},
kw...)::TCPSocket

p::UInt = isempty(port) ? UInt(80) : parse(UInt, port)
@debugv 2 "TCP connect: $host:$p..."
@debug "TCP connect: $host:$p..."
addrs = Sockets.getalladdrinfo(host)
err = ErrorException("failed to connect")
for addr in addrs
Expand Down Expand Up @@ -570,7 +570,7 @@ function getconnection(::Type{SSLContext},
kw...)::SSLContext

port = isempty(port) ? "443" : port
@debugv 2 "SSL connect: $host:$port..."
@debug "SSL connect: $host:$port..."
tcp = getconnection(TCPSocket, host, port; kw...)
return sslconnection(SSLContext, tcp, host; kw...)
end
Expand All @@ -581,7 +581,7 @@ function getconnection(::Type{SSLStream},
kw...)::SSLStream

port = isempty(port) ? "443" : port
@debugv 2 "SSL connect: $host:$port..."
@debug "SSL connect: $host:$port..."
tcp = getconnection(TCPSocket, host, port; kw...)
return sslconnection(SSLStream, tcp, host; kw...)
end
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Exceptions

export @try, HTTPError, ConnectError, TimeoutError, StatusError, RequestError, current_exceptions_to_string
using LoggingExtras, ExceptionUnwrapping
using ExceptionUnwrapping
import ..HTTP # for doc references

@eval begin
Expand Down
2 changes: 1 addition & 1 deletion src/HTTP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const DEBUG_LEVEL = Ref(0)

Base.@deprecate escape escapeuri

using Base64, Sockets, Dates, URIs, LoggingExtras, MbedTLS, OpenSSL
using Base64, Sockets, Dates, URIs, MbedTLS, OpenSSL

function access_threaded(f, v::Vector)
tid = Threads.threadid()
Expand Down
10 changes: 5 additions & 5 deletions src/Servers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,14 @@ function handle_connection(f, c::Connection, listener, readtimeout, access_log)
# attempt to read request line and headers
try
startread(http)
@debugv 1 "startread called"
@debug "startread called"
c.state = ACTIVE # once we've started reading, set ACTIVE state
catch e
# for ParserErrors, try to inform client of the problem
if e isa ParseError
write(c, Response(e.code == :HEADER_SIZE_EXCEEDS_LIMIT ? 431 : 400, string(e.code)))
end
@debugv 1 begin
@debug begin
msg = current_exceptions_to_string()
"handle_connection startread error. $msg"
end
Expand All @@ -465,15 +465,15 @@ function handle_connection(f, c::Connection, listener, readtimeout, access_log)

try
# invokelatest becuase the perf is negligible, but this makes live-editing handlers more Revise friendly
@debugv 1 "invoking handler"
@debug "invoking handler"
Base.invokelatest(f, http)
# If `startwrite()` was never called, throw an error so we send a 500 and log this
if isopen(http) && !iswritable(http)
error("Server never wrote a response.\n\n$request")
end
@debugv 1 "closeread"
@debug "closeread"
closeread(http)
@debugv 1 "closewrite"
@debug "closewrite"
closewrite(http)
c.state = IDLE
catch e
Expand Down
14 changes: 7 additions & 7 deletions src/Streams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Streams

export Stream, closebody, isaborted, setstatus, readall!

using Sockets, LoggingExtras
using Sockets
using ..IOExtras, ..Messages, ..Connections, ..Conditions, ..Exceptions
import ..HTTP # for doc references

Expand Down Expand Up @@ -132,7 +132,7 @@ function IOExtras.closewrite(http::Stream{<:Request})
http.message.version < v"1.1" &&
!hasheader(http.message, "Connection", "keep-alive")

@debugv 1 "\"Connection: close\": $(http.stream)"
@debug "\"Connection: close\": $(http.stream)"
close(http.stream)
end
end
Expand Down Expand Up @@ -166,7 +166,7 @@ https://tools.ietf.org/html/rfc7231#section-6.2.1
"""
function handle_continue(http::Stream{<:Response})
if http.message.status == 100
@debugv 1 "✅ Continue: $(http.stream)"
@debug "✅ Continue: $(http.stream)"
readheaders(http.stream, http.message)
end
end
Expand All @@ -176,7 +176,7 @@ function handle_continue(http::Stream{<:Request})
if !iswritable(http.stream)
startwrite(http.stream)
end
@debugv 1 "✅ Continue: $(http.stream)"
@debug "✅ Continue: $(http.stream)"
writeheaders(http.stream, Response(100))
end
end
Expand Down Expand Up @@ -361,9 +361,9 @@ function isaborted(http::Stream{<:Response})
if iswritable(http.stream) &&
iserror(http.message) &&
hasheader(http.message, "Connection", "close")
@debugv 1 "✋ Abort on $(sprint(writestartline, http.message)): " *
@debug "✋ Abort on $(sprint(writestartline, http.message)): " *
"$(http.stream)"
@debugv 2 "$(http.message)"
@debug "$(http.message)"
return true
end
return false
Expand All @@ -379,7 +379,7 @@ function IOExtras.closeread(http::Stream{<:Response})

if hasheader(http.message, "Connection", "close")
# Close conncetion if server sent "Connection: close"...
@debugv 1 "\"Connection: close\": $(http.stream)"
@debug "\"Connection: close\": $(http.stream)"
close(http.stream)
# Error if Message is not complete...
incomplete(http) && throw(EOFError())
Expand Down
28 changes: 14 additions & 14 deletions src/WebSockets.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module WebSockets

using Base64, LoggingExtras, UUIDs, Sockets, Random
using Base64, UUIDs, Sockets, Random
using MbedTLS: digest, MD_SHA1, SSLContext
using ..IOExtras, ..Streams, ..Connections, ..Messages, ..Conditions, ..Servers
using ..Exceptions: current_exceptions_to_string
Expand Down Expand Up @@ -373,7 +373,7 @@ function open(f::Function, url; suppress_close_error::Bool=false, verbose=false,
http.ntoread = 0
io = http.stream
ws = WebSocket(io, http.message.request, http.message; maxframesize, maxfragmentation)
@debugv 2 "$(ws.id): WebSocket opened"
@debug "$(ws.id): WebSocket opened"
try
f(ws)
catch e
Expand Down Expand Up @@ -423,7 +423,7 @@ listen(f, args...; kw...) = Servers.listen(http -> upgrade(f, http; kw...), args
listen!(f, args...; kw...) = Servers.listen!(http -> upgrade(f, http; kw...), args...; kw...)

function upgrade(f::Function, http::Streams.Stream; suppress_close_error::Bool=false, maxframesize::Integer=typemax(Int), maxfragmentation::Integer=DEFAULT_MAX_FRAG, nagle=false, quickack=true, kw...)
@debugv 2 "Server websocket upgrade requested"
@debug "Server websocket upgrade requested"
isupgrade(http.message) || handshakeerror()
if !hasheader(http, "Sec-WebSocket-Version", "13")
throw(WebSocketError("Expected \"Sec-WebSocket-Version: 13\"!\n" * "$(http.message)"))
Expand Down Expand Up @@ -451,7 +451,7 @@ function upgrade(f::Function, http::Streams.Stream; suppress_close_error::Bool=f
end

ws = WebSocket(io, req, req.response; client=false, maxframesize, maxfragmentation)
@debugv 2 "$(ws.id): WebSocket upgraded; connection established"
@debug "$(ws.id): WebSocket upgraded; connection established"
try
f(ws)
catch e
Expand Down Expand Up @@ -511,7 +511,7 @@ or `close(ws[, body::WebSockets.CloseFrameBody])`. Calling `close` will initiate
the close sequence and close the underlying connection.
"""
function Sockets.send(ws::WebSocket, x)
@debugv 2 "$(ws.id): Writing non-control message"
@debug "$(ws.id): Writing non-control message"
@require !ws.writeclosed
if !isbinary(x) && !istext(x)
# if x is not single binary or text, then assume it's an iterable of binary or text
Expand All @@ -524,7 +524,7 @@ function Sockets.send(ws::WebSocket, x)
x = ""
@goto write_single_frame
end
@debugv 2 "$(ws.id): Writing fragmented message"
@debug "$(ws.id): Writing fragmented message"
item, st = state
# we prefetch next state so we know if we're on the last item or not
# so we can appropriately set the FIN bit for the last fragmented frame
Expand Down Expand Up @@ -553,7 +553,7 @@ to when a PING message is received by a websocket connection.
"""
function ping(ws::WebSocket, data=UInt8[])
@require !ws.writeclosed
@debugv 2 "$(ws.id): sending ping"
@debug "$(ws.id): sending ping"
return writeframe(ws.io, Frame(true, PING, ws.client, payload(ws, data)))
end

Expand All @@ -568,7 +568,7 @@ used as a one-way heartbeat.
"""
function pong(ws::WebSocket, data=UInt8[])
@require !ws.writeclosed
@debugv 2 "$(ws.id): sending pong"
@debug "$(ws.id): sending pong"
return writeframe(ws.io, Frame(true, PONG, ws.client, payload(ws, data)))
end

Expand All @@ -584,7 +584,7 @@ frame.
"""
function Base.close(ws::WebSocket, body::CloseFrameBody=CloseFrameBody(1000, ""))
isclosed(ws) && return
@debugv 2 "$(ws.id): Closing websocket"
@debug "$(ws.id): Closing websocket"
ws.writeclosed = true
data = Vector{UInt8}(body.message)
prepend!(data, reinterpret(UInt8, [hton(UInt16(body.status))]))
Expand Down Expand Up @@ -676,10 +676,10 @@ returned by `receive`. Note that `WebSocket` objects can be iterated,
where each iteration yields a message until the connection is closed.
"""
function receive(ws::WebSocket)
@debugv 2 "$(ws.id): Reading message"
@debug "$(ws.id): Reading message"
@require !ws.readclosed
frame = readframe(ws.io, Frame, ws.readbuffer)
@debugv 2 "$(ws.id): Received frame: $frame"
@debug "$(ws.id): Received frame: $frame"
done = checkreadframe!(ws, frame)
# common case of reading single non-control frame
done && return frame.payload
Expand All @@ -689,16 +689,16 @@ function receive(ws::WebSocket)
payload = frame.payload
while true
frame = readframe(ws.io, Frame, ws.readbuffer, opcode)
@debugv 2 "$(ws.id): Received frame: $frame"
@debug "$(ws.id): Received frame: $frame"
done = checkreadframe!(ws, frame)
if !iscontrol(frame.flags.opcode)
payload = _append(payload, frame.payload)
@debugv 2 "$(ws.id): payload len = $(length(payload))"
@debug "$(ws.id): payload len = $(length(payload))"
end
done && break
end
payload isa String && utf8check(payload)
@debugv 2 "Read message: $(payload[1:min(1024, sizeof(payload))])"
@debug "Read message: $(payload[1:min(1024, sizeof(payload))])"
return payload
end

Expand Down
14 changes: 7 additions & 7 deletions src/clientlayers/ConnectionRequest.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ConnectionRequest

using URIs, Sockets, Base64, LoggingExtras, ConcurrentUtilities, ExceptionUnwrapping
using URIs, Sockets, Base64, ConcurrentUtilities, ExceptionUnwrapping
import MbedTLS
import OpenSSL
using ..Messages, ..IOExtras, ..Connections, ..Streams, ..Exceptions
Expand Down Expand Up @@ -68,7 +68,7 @@ function connectionlayer(handler)

userinfo = unescapeuri(url.userinfo)
if !isempty(userinfo) && !hasheader(req.headers, "Proxy-Authorization")
@debugv 1 "Adding Proxy-Authorization: Basic header."
@debug "Adding Proxy-Authorization: Basic header."
setheader(req.headers, "Proxy-Authorization" => "Basic $(base64encode(userinfo))")
end
else
Expand Down Expand Up @@ -134,7 +134,7 @@ function connectionlayer(handler)
if logerrors && !ExceptionUnwrapping.has_wrapped_exception(e, HTTPError)
@error current_exceptions_to_string() type=Symbol("HTTP.ConnectionRequest") method=req.method url=req.url context=req.context logtag=logtag
end
@debugv 1 "❗️ ConnectionLayer $root_err. Closing: $io"
@debug "❗️ ConnectionLayer $root_err. Closing: $io"
if @isdefined(stream) && stream.nwritten == -1
# we didn't write anything, so don't need to worry about
# idempotency of the request
Expand Down Expand Up @@ -210,17 +210,17 @@ end

function connect_tunnel(io, target_url, req)
target = "$(URIs.hoststring(target_url.host)):$(target_url.port)"
@debugv 1 "📡 CONNECT HTTPS tunnel to $target"
@debug "📡 CONNECT HTTPS tunnel to $target"
headers = Dict("Host" => target)
if (auth = header(req, "Proxy-Authorization"); !isempty(auth))
headers["Proxy-Authorization"] = auth
end
request = Request("CONNECT", target, headers)
# @debugv 2 "connect_tunnel: writing headers"
# @debug "connect_tunnel: writing headers"
writeheaders(io, request)
# @debugv 2 "connect_tunnel: reading headers"
# @debug "connect_tunnel: reading headers"
readheaders(io, request.response)
# @debugv 2 "connect_tunnel: done reading headers"
# @debug "connect_tunnel: done reading headers"
return request.response
end

Expand Down
2 changes: 1 addition & 1 deletion src/clientlayers/CookieRequest.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module CookieRequest

using Dates, LoggingExtras, URIs
using Dates, URIs
using ..Cookies, ..Messages, ..Strings

# default global cookie jar
Expand Down
6 changes: 3 additions & 3 deletions src/clientlayers/HeadersRequest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module HeadersRequest

export headerslayer, setuseragent!

using Base64, URIs, LoggingExtras
using Base64, URIs
using ..Messages, ..Forms, ..IOExtras, ..Sniff, ..Forms, ..Strings

"""
Expand All @@ -18,7 +18,7 @@ function headerslayer(handler)
if basicauth
userinfo = unescapeuri(req.url.userinfo)
if !isempty(userinfo) && !hasheader(headers, "Authorization")
@debugv 1 "Adding Authorization: Basic header."
@debug "Adding Authorization: Basic header."
setheader(headers, "Authorization" => "Basic $(base64encode(userinfo))")
end
end
Expand All @@ -29,7 +29,7 @@ function headerslayer(handler)

sn = sniff(bytes(req.body))
setheader(headers, "Content-Type" => sn)
@debugv 1 "setting Content-Type header to: $sn"
@debug "setting Content-Type header to: $sn"
end
## default headers
if isempty(req.url.port) ||
Expand Down
Loading

0 comments on commit c031311

Please sign in to comment.