
---@class socket_http_request*
---@field url? string URL。
---@field method? string HTTP method.
---@field headers? table<string, string> Request header.
---@field source? ltn12_source Request body source.
---@field sink? ltn12_sink Response body sink.
---@field body? string Request body.
---@field proxy? string Proxy URL.
---@field redirect? boolean Whether redirection is allowed.
---@field create? function socket Create function.

---@class socket_http_connection*
local socket_http_connection = {}

---@class socket_http*
---@field TIMEOUT number Default timeout.
---@field USERAGENT string Default User-Agent.
---@field genericform table Common request fields.
---@field schemes table<string, table> scheme configuration.
---@type socket_http*
local M = {}

M.TIMEOUT = 60
M.USERAGENT = nil
M.genericform = nil
M.schemes = nil

--- Open an HTTP connection.
---@param host string hostname.
---@param port? integer port.
---@param create? function socket Create function.
---@return socket_http_connection*? connection Connection object.
---@return string? errMsg error message.
function M.open(host, port, create) end

--- Make an HTTP request.
---@param request string|socket_http_request* URL or request form.
---@param body? string Request body.
---@return string|integer|nil bodyOrOk Response body or LTN12 status.
---@return integer|string? statusCodeOrErr Status code or error message.
---@return table? headers response header.
---@return string? statusLine status line.
function M.request(request, body) end

--- LuaSocket try function.
---@param ... any value.
---@return any ... Non-error return value.
function M.try(...) end

--- Close the connection.
---@return any result Close results.
function socket_http_connection:close() end

return M
