summaryrefslogtreecommitdiff
path: root/script/async
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-06-22 14:10:46 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-06-22 14:10:46 +0800
commitb3562693c86c30d6d762d1720e8660b9006273e0 (patch)
tree1b6e45a3f247b8e141a35fb19734b532445ba08d /script/async
parent7ace5187167710fe3cf58c20282a32d3ccbdc9ac (diff)
downloadlua-language-server-b3562693c86c30d6d762d1720e8660b9006273e0.zip
fix #182
Diffstat (limited to 'script/async')
-rw-r--r--script/async/proto.lua42
1 files changed, 26 insertions, 16 deletions
diff --git a/script/async/proto.lua b/script/async/proto.lua
index 3e7fcc60..f0b23dae 100644
--- a/script/async/proto.lua
+++ b/script/async/proto.lua
@@ -9,25 +9,35 @@ local function pushError(...)
ERR:push(buf)
end
-local function readProtoHeader()
- local header = io.read 'l'
- if header:sub(1, #'Content-Length') == 'Content-Length' then
- return header
- elseif header:sub(1, #'Content-Type') == 'Content-Type' then
- return nil
- else
- pushError('Proto header error:', header)
- return nil
+local function readProtoHead(reader)
+ local head = {}
+ while true do
+ local line = reader 'L'
+ if line == '\r\n' then
+ break
+ else
+ local k, v = line:match '^([^:]+)%s*%:%s*(.+)\r\n$'
+ if k then
+ if k == 'Content-Length' then
+ v = tonumber(v)
+ end
+ head[k] = v
+ else
+ pushError('Proto header error:', head)
+ break
+ end
+ end
end
+ return head
end
-local function readProtoContent(header)
- local len = tonumber(header:match('%d+'))
+local function readProtoContent(head)
+ local len = head['Content-Length']
if not len then
- pushError('Proto header error:', header)
+ pushError('Proto header error:', head)
return nil
end
- local buf = io.read(len+2)
+ local buf = io.read(len)
if not buf then
return nil
end
@@ -40,11 +50,11 @@ local function readProtoContent(header)
end
local function readProto()
- local header = readProtoHeader()
- if not header then
+ local head = readProtoHead(io.read)
+ if not head then
return
end
- local data = readProtoContent(header)
+ local data = readProtoContent(head)
if not data then
return
end