@@ -7,6 +7,17 @@ let m = match(r"^libcurl/(\d+\.\d+\.\d+)\b", CURL_VERSION_STR)
77 const global USER_AGENT = " curl/$curl julia/$julia "
88end
99
10+ struct NoChannel end
11+ const NOCHANNEL = NoChannel ()
12+
13+
14+ Base. isopen (req:: NoChannel ) = false
15+ Base. isempty (req:: NoChannel ) = true
16+ Base. put! (req:: NoChannel , :: IOBuffer ) = false
17+ Base. take! (req:: NoChannel ) = nothing
18+ Base. close (req:: NoChannel ) = false
19+ Base. iterate (req:: NoChannel ) = Iterators. Stateful (Iterators. flatten (Iterators. repeated (nothing , 0 )))
20+
1021
1122function write_callback (
1223 data:: Ptr{Cchar} ,
@@ -122,10 +133,16 @@ function header_callback(
122133 header = unsafe_string (data, n)
123134 header = strip (header)
124135
125- if (m_grpc_status = match (regex_grpc_status, header)) != = nothing
126- req. grpc_status = parse (UInt64, m_grpc_status. captures[1 ])
127- elseif (m_grpc_message = match (regex_grpc_message, header)) != = nothing
128- req. grpc_message = m_grpc_message. captures[1 ]
136+ if (m_grpc_status = match (regex_grpc_status, header)) isa RegexMatch
137+ capture = m_grpc_status. captures[1 ]
138+ if capture != = nothing
139+ req. grpc_status = parse (UInt64, capture)
140+ end
141+ elseif (m_grpc_message = match (regex_grpc_message, header)) isa RegexMatch
142+ capture = m_grpc_message. captures[1 ]
143+ if capture != = nothing
144+ req. grpc_message = capture
145+ end
129146 end
130147
131148 return n
@@ -155,6 +172,7 @@ function grpc_timeout_header_val(timeout::Real)
155172 return " $(string (timeout_nanosecs)) n"
156173end
157174
175+
158176mutable struct gRPCRequest
159177 # CURL multi lock for exclusive access to the easy handle after its added to the multi
160178 lock:: ReentrantLock
@@ -179,8 +197,8 @@ mutable struct gRPCRequest
179197 response:: IOBuffer
180198
181199 # These are only used when the request or response is streaming
182- request_c:: Union{Nothing, Channel{IOBuffer}}
183- response_c:: Union{Nothing, Channel{IOBuffer}}
200+ request_c:: Union{Channel{IOBuffer}, NoChannel }
201+ response_c:: Union{Channel{IOBuffer}, NoChannel }
184202
185203 # The task making the request can block on this until the request is complete
186204 ready:: Event
@@ -210,11 +228,11 @@ mutable struct gRPCRequest
210228
211229 function gRPCRequest (
212230 grpc,
213- url,
231+ url:: String ,
214232 request:: IOBuffer ,
215233 response:: IOBuffer ,
216- request_c:: Union{Nothing, Channel{IOBuffer}} ,
217- response_c:: Union{Nothing, Channel{IOBuffer}} ;
234+ request_c:: Union{Channel{IOBuffer}, NoChannel } ,
235+ response_c:: Union{Channel{IOBuffer}, NoChannel } ;
218236 deadline = 10 ,
219237 keepalive = 60 ,
220238 max_send_message_length = 4 * 1024 * 1024 ,
@@ -353,8 +371,10 @@ function handle_exception(req::gRPCRequest, ex; notify_ready = false)
353371 end
354372end
355373
356- isstreaming_request (req:: gRPCRequest ) = ! isnothing (req. request_c)
357- isstreaming_response (req:: gRPCRequest ) = ! isnothing (req. response_c)
374+
375+ isstreaming_request (req:: gRPCRequest ) = ! isa (req. request_c, NoChannel)
376+ isstreaming_response (req:: gRPCRequest ) = ! isa (req. response_c, NoChannel)
377+
358378
359379Base. wait (req:: gRPCRequest ) = wait (req. ready)
360380
@@ -683,7 +703,7 @@ mutable struct gRPCCURL
683703 # Allows for controlling the maximum number of concurrent gRPC requests/streams
684704 events:: Channel{Event}
685705
686- function gRPCCURL (max_streams = GRPC_MAX_STREAMS)
706+ function gRPCCURL (max_streams:: Int = GRPC_MAX_STREAMS)
687707 grpc = new (
688708 Ptr {Cvoid} (0 ),
689709 ReentrantLock (),
0 commit comments