lua-Spore: change of "Format" middlewares is proposed

24 views
Skip to first unread message

Valeriy Skurikhin

unread,
Sep 2, 2011, 12:12:45 PM9/2/11
to SPORE
While implementing description file and tests for Redmine REST API
I've encountered situation, when "Format.XML" midleware throws an
error due to dubious server response. Usually, when you send PUT
request, you get a response with void body, this is what "Format.XML"
expects. Here the code:

function m:call (req)
[... some code ...]
return function (res)
if res.body and res.body ~= '' then
local r, msg = xml.parse(res.body)
[... some code ...]
end
return res
end
end

But Redmine server returns a response with the body consisting form
one space sybmol instead, which leads to xml parsing error. The same
problem exists with "Format.JSON" and "Format.YAML" also. I had to
replace this condition with "if res.body and res.body:gsub(' ', '') ~=
'' then" in order to make my test works.

My question is: would it be usefull to pull this changes into the main
repository, or such response should be considered as incorrect and
it's a problem of the Redmine, not lua-spore?

PS: Perhaps "if res.body and res.body:gsub('%s', '') ~= '' then" will
work better?

Alexander Gladysh

unread,
Sep 3, 2011, 10:46:23 AM9/3/11
to spore...@googlegroups.com

Or maybe just trim the response string.

* * *

This is clearly a Redmine problem, not lua-Spore one — they should
respond with some XML data.

However, buggy server implementations will always be there, no matter
what. It would be great if lua-Spore would allow specification writer
to handle them.

Of course, the bug in server must be fixed, but there are thousands of
Redmine installations out there — who knows when they would be
updated, and, furthermore Redmine is released only once in every six
months. Developers just have to live with that.

Same reasoning holds true for any server out there. Bugs, of course
must be reported and fixed, but it takes time, and the code should
work "now". :-)

François, what do you think?

I, myself, do not think that the suggested solution is generic enough
to be included in lua-Spore, but, maybe, you could allow service
description author to provide a pre-filter function for server
response string, or something like this?

Thanks,
Alexander.

fperrad

unread,
Sep 4, 2011, 9:31:44 AM9/4/11
to SPORE


On Sep 3, 4:46 pm, Alexander Gladysh <aglad...@gmail.com> wrote:
I agree, the real world must be taken in account.

Before version 0.1.2, the test is only :
if res.body then
with the commit https://github.com/fperrad/lua-Spore/commit/330bde0bbde2e6610ce1dc256c174ddb53a7b365,
it becomes :
if res.body and res.body ~= '' then

In my point of view (I am a regexp fan), the next step is :
if res.body and not res.body:match'^%s*$' then
or (when paranoia is a good thing) :
if type(res.body) == 'string' and not res.body:match'^%s*$' then

François

Alexander Gladysh

unread,
Sep 4, 2011, 9:43:56 AM9/4/11
to spore...@googlegroups.com

Shouldn't the regexp be something like '^%s*%S.*$'? Or am I missing the point?

> or (when paranoia is a good thing) :
>    if type(res.body) == 'string' and not res.body:match'^%s*$' then

Well, that approach should work for us, so, no problem.

Can you please make that change in the code?

Thanks,
Alexander.

fperrad

unread,
Sep 4, 2011, 10:20:31 AM9/4/11
to SPORE


On Sep 4, 3:43 pm, Alexander Gladysh <aglad...@gmail.com> wrote:
> > with the commithttps://github.com/fperrad/lua-Spore/commit/330bde0bbde2e6610ce1dc256...,
> > it becomes :
> >    if res.body and res.body ~= '' then
>
> > In my point of view (I am a regexp fan), the next step is :
> >    if res.body and not res.body:match'^%s*$' then
>
> Shouldn't the regexp be something like '^%s*%S.*$'? Or am I missing the point?

the current code could be rewritten :
if res.body and not res.body == '' then
and my proposal is :
if res.body and not res.body:match'^%s*$' then

so, I think you miss the *not*.

François

Franck Cuny

unread,
Sep 4, 2011, 11:26:57 AM9/4/11
to spore...@googlegroups.com

yes, we definitely need to realize that it's a "not common" case, and
common middle wares provided with SPORE should only take care about
common case. That's the reason I wanted middle wares in SPORE, so you
don't have to put all the weird cases in core.

>>
>> > Before version 0.1.2, the test is only :
>> >    if res.body then
>> > with the commithttps://github.com/fperrad/lua-Spore/commit/330bde0bbde2e6610ce1dc256...,
>> > it becomes :
>> >    if res.body and res.body ~= '' then
>>
>> > In my point of view (I am a regexp fan), the next step is :
>> >    if res.body and not res.body:match'^%s*$' then
>>
>> Shouldn't the regexp be something like '^%s*%S.*$'? Or am I missing the point?
>
> the current code could be rewritten :
>    if res.body and not res.body == '' then
> and my proposal is :
>    if res.body and not res.body:match'^%s*$' then
>
> so, I think you miss the *not*.
>
> François

that's a good solution. I'll also apply this on Net::HTTP::Spore in
the Perl land.

>
>>
>> > or (when paranoia is a good thing) :
>> >    if type(res.body) == 'string' and not res.body:match'^%s*$' then
>>
>> Well, that approach should work for us, so, no problem.
>>
>> Can you please make that change in the code?
>>
>> Thanks,
>> Alexander.

--
franck cuny

Alexander Gladysh

unread,
Sep 5, 2011, 5:14:59 AM9/5/11
to spore...@googlegroups.com

Ah, yes, of course :-)

Thanks,
Alexander.

Reply all
Reply to author
Forward
0 new messages