Wait for chunked stream WIP [CI SKIP]

cron
Jef Roosens 2022-02-20 12:35:10 +01:00
parent e6a1d32f0e
commit 275227400f
Signed by untrusted user: Jef Roosens
GPG Key ID: B580B976584B5F30
2 changed files with 13 additions and 8 deletions

View File

@ -4,4 +4,5 @@ import docker
fn build() {
println(docker.pull('archlinux', 'latest') or { panic('yeetus') })
// println(docker.containers() or { panic('heet') })
}

View File

@ -23,23 +23,27 @@ fn send(req &string) ?http.Response {
// Write the request to the socket
s.write_string(req) ?
// Wait for the server to respond
s.wait_for_write() ?
mut buf := []byte{len: docker.buf_len}
mut res := []byte{}
mut c := 0
for {
c = s.read(mut buf) or { return error('Failed to read data from socket.') }
res << buf[..c]
for res.len < 5 && res#[-4..] != [0, '\r', `\n`, `\r`, `\n`] {
// Wait for the server to respond
s.wait_for_write() ?
if c < docker.buf_len {
break
for {
c = s.read(mut buf) or { return error('Failed to read data from socket.') }
res << buf[..c]
if c < docker.buf_len {
break
}
}
}
println(res)
// Decode chunked response
return http.parse_response(res.bytestr())