@@ -223,7 +223,44 @@ function Base.readavailable(http::Stream)::ByteView
223
223
return bytes
224
224
end
225
225
226
- IOExtras. unread! (http:: Stream , excess) = unread! (http. stream, excess)
226
+ function IOExtras. unread! (http:: Stream , excess)
227
+
228
+ if http. readchunked && http. ntoread == unknown_length
229
+ # If the whole chunk was read, unread! needs to push
230
+ # back the CRLF that came after the chunk data
231
+ # (See readavailable above).
232
+ excess = view (excess. parent, excess. indexes[1 ]. start:
233
+ excess. indexes[1 ]. stop + 2 )
234
+ http. ntoread = length (excess)
235
+
236
+ elseif http. ntoread != unknown_length
237
+ http. ntoread += length (excess)
238
+ end
239
+
240
+ unread! (http. stream, excess)
241
+ end
242
+
243
+ @static if VERSION < v " 0.7.0-DEV.2005"
244
+
245
+ find_delim (bytes, d:: UInt8 ) = findfirst (x-> x== d, bytes)
246
+
247
+ Base. readuntil (http:: Stream , delim:: UInt8 ) =
248
+ Vector {UInt8} (readuntil (http, bytes-> find_delim (bytes, delim)))
249
+ # See readuntil(::IO, ::Function) in IOExtras.jl
250
+
251
+ else
252
+
253
+ find_delim (bytes, d:: UInt8 ) =
254
+ (i = findfirst (equalto (d), bytes)) == nothing ? 0 : i
255
+
256
+ function Base. readuntil (http:: Stream , delim:: UInt8 ; keep:: Bool = false )
257
+ bytes = readuntil (http, bytes-> find_delim (bytes, delim))
258
+ if keep == false
259
+ bytes = view (bytes, 1 : length (bytes)- 1 )
260
+ end
261
+ return Vector {UInt8} (bytes)
262
+ end
263
+ end
227
264
228
265
function Base. read (http:: Stream )
229
266
buf = IOBuffer ()
0 commit comments