Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple_request.lua from examples fails when response is json #82

Closed
kcsoft opened this issue Oct 27, 2017 · 7 comments
Closed

simple_request.lua from examples fails when response is json #82

kcsoft opened this issue Oct 27, 2017 · 7 comments
Labels

Comments

@kcsoft
Copy link

kcsoft commented Oct 27, 2017

when running:
lua simple_reuqest.lua https://jsonplaceholder.typicode.com/posts/1
getting an error when reading the response body:
lua: (error object is not a string)

For text/html responses I'm getting the response just fine.

I'm testing this on openwrt x86 15.05, lua-http v0.2.

@daurnimator
Copy link
Owner

I was able to hit that url without issue:

$ lua examples/simple_request.lua https://jsonplaceholder.typicode.com/posts/1
# REQUEST
## HEADERS
:method	GET
:authority	jsonplaceholder.typicode.com
:path	/posts/1
:scheme	https
user-agent	lua-http/0.2

# RESPONSE
## HEADERS
:status	200
date	Fri, 27 Oct 2017 09:43:24 GMT
content-type	application/json; charset=utf-8
content-length	292
set-cookie	__cfduid=ddbcd18cb1de33e8f5d3ae6a445fb4c1e1509097404; expires=Sat, 27-Oct-18 09:43:24 GMT; path=/; domain=.typicode.com; HttpOnly
x-powered-by	Express
vary	Origin, Accept-Encoding
access-control-allow-credentials	true
cache-control	public, max-age=14400
pragma	no-cache
expires	Fri, 27 Oct 2017 13:43:24 GMT
x-content-type-options	nosniff
etag	W/"124-yiKdLzqO5gfBrJFrcdJ8Yq0LGnU"
via	1.1 vegur
cf-cache-status	REVALIDATED
server	cloudflare-nginx
cf-ray	3b44b5f8fa688460-HKG

## BODY
{
  "userId": 1,
  "id": 1,
  "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
  "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}

simple_request.lua explicitly calls tostring on errors, so I'm not sure where you're getting the error from.

Could you try and narrow it down for me?

@kcsoft
Copy link
Author

kcsoft commented Oct 27, 2017

Thank you for your help. It looks that the issue is platform specific. I'll try to debug through lua-http and get back with results.

@kcsoft
Copy link
Author

kcsoft commented Oct 27, 2017

The issue comes from lua interpreting number ranges in h2_stream.lua
On OpenWrt 15.05, Lua 5.1
The issue is that:

# lua -e "print(1 >= 0x7fffffff)"
false
# lua -e "print(1 >= 0x80000000)"
true

I tried this test http://lua-users.org/wiki/IntegerDomain
Works fine, I get

supported integer range is: -9.0071992547409920e+15...+9.0071992547409920e+15

@daurnimator
Copy link
Owner

# lua -e "print(1 >= 0x80000000)
true

That lua behaviour is not compliant to the lua manual, such behaviour is sure to break plenty of lua code!
Looks like they have a few patches that make their lua non-standard: https://github.com/openwrt/openwrt/tree/5ce38c486c525b28d9784f83e839537aa0149123/package/utils/lua/patches

However, a similar issue I've realised might exist is lua 5.3 compiled with -DLUA_INT_TYPE=LUA_INT_INT. I'll commit a fix for that, and perhaps you could retry?

daurnimator added a commit that referenced this issue Oct 28, 2017
The literal 0x80000000 might have overflowed in lua 5.3 if lua was compiled with `-DLUA_INT_TYPE=LUA_INT_INT`.

Related to #82
@kcsoft
Copy link
Author

kcsoft commented Oct 28, 2017

Tested with your commit and it works fine now. Feel free to close the issue.
Thank you.

@kcsoft kcsoft closed this as completed Oct 28, 2017
@kcsoft kcsoft reopened this Oct 28, 2017
@daurnimator
Copy link
Owner

@kcsoft did you mean to reopen?

@kcsoft
Copy link
Author

kcsoft commented Oct 29, 2017

All good, closing.

@kcsoft kcsoft closed this as completed Oct 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants