progress for httpclient
This commit is contained in:
parent
d318f2eb35
commit
35afc48154
1 changed files with 39 additions and 11 deletions
|
|
@ -68,19 +68,47 @@ proc parseBody(data: var string, start: int, s: TSocket,
|
||||||
while data[i] notin {'\C', '\L', '\0'}: inc(i)
|
while data[i] notin {'\C', '\L', '\0'}: inc(i)
|
||||||
if data[i] == '\C': inc(i)
|
if data[i] == '\C': inc(i)
|
||||||
if data[i] == '\L': inc(i)
|
if data[i] == '\L': inc(i)
|
||||||
|
echo "ChunkSize: ", chunkSize
|
||||||
if chunkSize <= 0: break
|
if chunkSize <= 0: break
|
||||||
result.add(copy(data, i, i+chunkSize-1))
|
|
||||||
if i + chunkSize > data.len:
|
|
||||||
echo "i: ", i, " size: ", chunkSize, " len: ", data.len
|
|
||||||
|
|
||||||
assert(i + chunkSize <= data.len)
|
var x = copy(data, i, i+chunkSize-1)
|
||||||
i = i + chunkSize
|
var size = x.len
|
||||||
|
result.add(x)
|
||||||
|
|
||||||
|
if size < chunkSize:
|
||||||
|
# read in the rest:
|
||||||
|
var missing = chunkSize - size
|
||||||
|
var L = result.len
|
||||||
|
setLen(result, L + missing)
|
||||||
|
discard s.recv(addr(result[L]), missing)
|
||||||
|
|
||||||
|
#var c: char
|
||||||
|
#discard s.recv(addr(c), sizeof(c))
|
||||||
|
#if c == '\C': discard s.recv(addr(c), sizeof(c))
|
||||||
|
#if c != '\L': httpError("CRLF missing: " & c)
|
||||||
|
|
||||||
|
# next chunk:
|
||||||
|
data = s.recv()
|
||||||
|
echo data
|
||||||
|
i = 0
|
||||||
|
when false:
|
||||||
|
# chunk may be bigger than what we got:
|
||||||
|
while size < chunkSize:
|
||||||
|
data = s.recv()
|
||||||
|
echo "currsize: ", size, " chunksize: ", chunkSize, " dlen ", data.len
|
||||||
|
if size + data.len <= chunkSize:
|
||||||
|
result.add(data)
|
||||||
|
inc(size, data.len)
|
||||||
|
else:
|
||||||
|
i = chunkSize-size
|
||||||
|
var x = copy(data, 0, i-1)
|
||||||
|
result.add(x)
|
||||||
|
inc(size, x.len)
|
||||||
|
#break
|
||||||
|
|
||||||
# skip trailing CR-LF:
|
# skip trailing CR-LF:
|
||||||
#if data[i] == '\C': inc(i)
|
while data[i] in {'\C', '\L'}: inc(i)
|
||||||
#if data[i] == '\L': inc(i)
|
|
||||||
|
|
||||||
echo "came here"
|
|
||||||
data.add(s.recv())
|
|
||||||
else:
|
else:
|
||||||
result = copy(data, start)
|
result = copy(data, start)
|
||||||
# -REGION- Content-Length
|
# -REGION- Content-Length
|
||||||
|
|
@ -199,4 +227,4 @@ proc downloadFile*(url: string, outputFilename: string) =
|
||||||
|
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
downloadFile("http://www.google.com", "GoogleTest.txt")
|
downloadFile("http://www.google.com", "GoogleTest.html")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue