Closed otgo closed 4 years ago
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.
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
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.
Tracked in https://github.com/wahern/luaossl/issues/172
I tried your code, really this is enough:
local openssl_ctx = require "openssl.ssl.context"
Maybe in lua_open_xx ?
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?
@otgo ?
I tried again and it works XD i dont know why... sorry, i was busy at work these months
How do I do this in lua-http?