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

Question #153

Closed
otgo opened this issue Jun 8, 2019 · 8 comments
Closed

Question #153

otgo opened this issue Jun 8, 2019 · 8 comments
Labels

Comments

@otgo
Copy link

otgo commented Jun 8, 2019

How do I do this in lua-http?

-- I added here the libraries that I've used just in case.
https = require 'ssl.https'
ltn = require 'ltn12' 
https.request {
        ['url'] = self.URL..method,
        ['method'] = 'POST',
        ['headers'] = {
            ['Content-Type'] = ('%s; boundary=%s'):format('multipart/form-data', boundary),
            ['Content-Length'] = #source[1]
        },
        ['source'] = ltn12.source.string(source[1]),
        ['sink'] = ltn12.sink.table(response)
    }
@daurnimator
Copy link
Owner

You can just swap https = require 'ssl.https' for https = require "http.compat.socket". See https://daurnimator.github.io/lua-http/0.3/#http.compat.socket
Otherwise I'm going to need a lot more context.

@otgo
Copy link
Author

otgo commented Jun 16, 2019

I did recently a test, all it's okay now, it is working good, but returns this:
Segmentation Fault (core dumped)
Like a C error...

Here my debug code:

local https = require 'http.compat.socket'
--https = require 'ssl.https'
local ltn12 = require 'ltn12'
function tprintf(_table_, _index_, _string_, ...)
	if not _table_[_index_] then
		_table_[_index_] = ''
	end
	_table_[_index_] = _table_[_index_] .. string.format(_string_, ...)
end
local source = {}
local response = {}
local index = 1
local boundary = 'BOUNDARY--mdd4s4Sd457dOp--END'
tprintf(source, index, '--%s\r\n', boundary)
tprintf(source, index, 'Content-Disposition: form-data; name="%s"\r\n\r\n', 'text')
tprintf(source, index, '%s\r\n', 'This is a test; sendMessage();')
tprintf(source, index, '--%s\r\n', boundary)
tprintf(source, index, 'Content-Disposition: form-data; name="%s"\r\n\r\n', 'chat_id')
tprintf(source, index, '%s\r\n', "189041244")
tprintf(source, index, '--%s--\r\n', boundary)
print(boundary)
https.request {
	['url'] = 'https://api.telegram.org/bot213210238:AAEP1XgZOXjIiAqDJvUEDBzBHmLqAzO3Rug/sendMessage',
	['method'] = 'POST',
	['headers'] = {
		['Content-Type'] = ('%s; boundary=%s'):format('multipart/form-data', boundary),
		['Content-Length'] = #source[index]
	},
	['source'] = ltn12.source.string(source[index]),
	['sink'] = ltn12.sink.table(response)
}
print(table.concat(response))

Did you fixed that recently ?
Or have I something wrong in my code?

EDIT: I did a test compiling from source and i got the same

@daurnimator
Copy link
Owner

Ah ha, yes that segfaults for me too! I think it's a bug in luaossl. Simply

local openssl_ctx = require "openssl.ssl.context"
local openssl_pkey = require "openssl.pkey"

local ctx = openssl_ctx.new("TLS", false)
ctx:setEphemeralKey(openssl_pkey.new{ type = "EC", curve = "prime256v1" })

Is enough to segfault.

@daurnimator
Copy link
Owner

Tracked in wahern/luaossl#172

@otgo
Copy link
Author

otgo commented Jun 16, 2019

I tried your code, really this is enough:

local openssl_ctx = require "openssl.ssl.context"

Maybe in lua_open_xx ?

@daurnimator
Copy link
Owner

I tried your code, really this is enough:

local openssl_ctx = require "openssl.ssl.context"

Maybe in lua_open_xx ?

In that case you might be having a different issue. Could you share how you install lua-http's dependencies? And your OS/distro?

@daurnimator
Copy link
Owner

@otgo ?

@otgo
Copy link
Author

otgo commented Jul 31, 2019

I tried again and it works XD i dont know why... sorry, i was busy at work these months

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