Skip to content

Commit

Permalink
Fix typo and repush http_req improvment
Browse files Browse the repository at this point in the history
  • Loading branch information
exebetche committed Sep 21, 2014
1 parent 57f8546 commit e8f5d64
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions vlsub.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1866,31 +1866,37 @@ function http_req(host, port, request)
vlc.net.send(fd, request)
vlc.net.poll(pollfds)

local response = vlc.net.recv(fd, 2048)
local headerStr, body = string.match(response, "(.-\r?\n)\r?\n(.*)")
local header = parse_header(headerStr)
local contentLength = tonumber(header["Content-Length"])
local TransferEncoding = header["Transfer-Encoding"]
local status = tonumber(header["statuscode"])
local bodyLenght = string.len(body)
local chunk = vlc.net.recv(fd, 2048)
local response = ""
local headerStr, header, body
local contentLength, status
local pct = 0

--~ if status ~= 200 then return status end

while contentLength and bodyLenght < contentLength do
vlc.net.poll(pollfds)
response = vlc.net.recv(fd, 1024)
while chunk do
response = response..chunk
if not header then
headerStr, body = response:match("(.-\r?\n)\r?\n(.*)")
if headerStr then
response = body
header = parse_header(headerStr)
contentLength = tonumber(header["Content-Length"])
status = tonumber(header["statuscode"])
end
end

if response then
body = body..response
else
vlc.net.close(fd)
return false
if contentLength then
bodyLenght = #response
pct = bodyLenght / contentLength * 100
setMessage(openSub.actionLabel..": "..progressBarContent(pct))
if bodyLenght >= contentLength then
break
end
end
bodyLenght = string.len(body)
pct = bodyLenght / contentLength * 100
setMessage(openSub.actionLabel..": "..progressBarContent(pct))

vlc.net.poll(pollfds)
chunk = vlc.net.recv(fd, 1024)
end

vlc.net.close(fd)

if status == 301
Expand All @@ -1901,9 +1907,9 @@ function http_req(host, port, request)
:gsub("(Host: )([^\n]*)", "%1"..host)

return http_req(host, port, request)
end
return status, body
end

return status, response
end

function parse_header(data)
Expand Down

0 comments on commit e8f5d64

Please sign in to comment.