keplerproject/wsapi — pull request #14 by ignacio (2013-04-19 15:29:16+00:00)
Title: Mock requests return wrong data when reading

Reading data in chunk from the request yields the wrong data:

~~~lua
local mock = require "wsapi.mock"
local ws_request = require "wsapi.request"

local test_app = function(wsapi_env)

return 200, {}, coroutine.wrap(function()
coroutine.yield(wsapi_env.input:read(2048))
coroutine.yield(wsapi_env.input:read(2048))
end)
end

local app = mock.make_handler(test_app)

local data = ("AB"):rep(1024) .. ("CD"):rep(1024)
local response, request = app:post("test", data, { ["Content-Length"] = #data, ["Content-Type"] = "text/plain" })

assert(response.body == data)
~~~~

The problem is here:
https://github.com/keplerproject/wsapi/blob/master/src/wsapi/mock.lua#L74

It should be:
~~~lua
local s = self.buffer:sub(self.bytes_read + 1, self.bytes_read + len)
~~~~