mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-07-13 14:14:30 +02:00
Compare commits
16 Commits
hjelmeland
...
f815d7005c
Author | SHA1 | Date | |
---|---|---|---|
f815d7005c | |||
23241717bf | |||
98be8d9fc1 | |||
fa69770e52 | |||
13f2b3c663 | |||
453a5207ed | |||
de359ea408 | |||
c93f9154e1 | |||
b281e6f717 | |||
784b0631e1 | |||
a1b5d3abd1 | |||
8a5368b659 | |||
22b8202d70 | |||
3a817a56eb | |||
7eaf648056 | |||
bef62aeb50 |
@ -89,7 +89,7 @@ it should be easy to use LuaSocket. Just fire the interpreter and use the
|
||||
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
|
||||
> socket = require("socket")
|
||||
> print(socket._VERSION)
|
||||
--> LuaSocket 3.0.0
|
||||
--> LuaSocket 3.1.0
|
||||
</pre>
|
||||
|
||||
<p> Each module loads their dependencies automatically, so you only need to
|
||||
|
@ -40,7 +40,7 @@ Pump, Support, Library">
|
||||
<h2 id="ltn12">LTN12</h2>
|
||||
|
||||
<p> The <tt>ltn12</tt> namespace implements the ideas described in
|
||||
<a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">
|
||||
LTN012, Filters sources and sinks</a>. This manual simply describes the
|
||||
functions. Please refer to the LTN for a deeper explanation of the
|
||||
functionality provided by this module.
|
||||
|
@ -164,6 +164,9 @@ Creates and returns a <em>clean</em>
|
||||
<a href="#try"><tt>try</tt></a>
|
||||
function that allows for cleanup before the exception
|
||||
is raised.
|
||||
This implements the ideas described in
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn013.md">
|
||||
LTN012, Using finalized exceptions</a>.
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
@ -207,6 +210,9 @@ Converts a function that throws exceptions into a safe function. This
|
||||
function only catches exceptions thrown by the <a href="#try"><tt>try</tt></a>
|
||||
and <a href="#newtry"><tt>newtry</tt></a> functions. It does not catch normal
|
||||
Lua errors.
|
||||
This implements the ideas described in
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn013.md">
|
||||
LTN012, Using finalized exceptions</a>.
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
@ -425,6 +431,9 @@ socket.<b>try(</b>ret<sub>1</sub> [, ret<sub>2</sub> ... ret<sub>N</sub>]<b>)</b
|
||||
Throws an exception in case <tt>ret<sub>1</sub></tt> is falsy, using
|
||||
<tt>ret<sub>2</sub></tt> as the error message. The exception is supposed to be caught
|
||||
by a <a href="#protect"><tt>protect</tt></a>ed function only.
|
||||
This implements the ideas described in
|
||||
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn013.md">
|
||||
LTN012, Using finalized exceptions</a>.
|
||||
</p>
|
||||
|
||||
<p class="parameters">
|
||||
|
@ -60,7 +60,7 @@ An URL is defined by the following grammar:
|
||||
|
||||
<blockquote>
|
||||
<tt>
|
||||
<url> ::= [<scheme>:][//<authority>][/<path>][;<params>][?<query>][#<fragment>]<br>
|
||||
<url> ::= [<scheme>:][//<authority>][/<path>][?<query>][#<fragment>]<br>
|
||||
<authority> ::= [<userinfo>@]<host>[:<port>]<br>
|
||||
<userinfo> ::= <user>[:<password>]<br>
|
||||
<path> ::= {<segment>/}<segment><br>
|
||||
@ -225,7 +225,6 @@ parsed_url = {<br>
|
||||
scheme = <i>string</i>,<br>
|
||||
authority = <i>string</i>,<br>
|
||||
path = <i>string</i>,<br>
|
||||
params = <i>string</i>,<br>
|
||||
query = <i>string</i>,<br>
|
||||
fragment = <i>string</i>,<br>
|
||||
userinfo = <i>string</i>,<br>
|
||||
@ -255,7 +254,6 @@ parsed_url = url.parse("ftp://root:passwd@unsafe.org/pub/virus.exe;type=i")
|
||||
-- scheme = "ftp",
|
||||
-- authority = "root:passwd@unsafe.org",
|
||||
-- path = "/pub/virus.exe",
|
||||
-- params = "type=i",
|
||||
-- userinfo = "root:passwd",
|
||||
-- host = "unsafe.org",
|
||||
-- user = "root",
|
||||
|
@ -69,6 +69,7 @@ local function make_plat(plat)
|
||||
["socket.smtp"] = "src/smtp.lua",
|
||||
ltn12 = "src/ltn12.lua",
|
||||
socket = "src/socket.lua",
|
||||
mbox = "src/mbox.lua",
|
||||
mime = "src/mime.lua"
|
||||
}
|
||||
if plat == "unix"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#--------------------------------------------------------------------------
|
||||
# Distribution makefile
|
||||
#--------------------------------------------------------------------------
|
||||
DIST = luasocket-3.0.0
|
||||
DIST = luasocket-3.1.0
|
||||
|
||||
TEST = \
|
||||
test/README \
|
||||
|
20
src/http.lua
20
src/http.lua
@ -54,7 +54,7 @@ local function receiveheaders(sock, headers)
|
||||
while line ~= "" do
|
||||
-- get field-name and value
|
||||
name, value = socket.skip(2, string.find(line, "^(.-):%s*(.*)"))
|
||||
if not (name and value) then return nil, "malformed reponse headers" end
|
||||
if not (name and value) then return nil, "malformed response headers" end
|
||||
name = string.lower(name)
|
||||
-- get next line (value might be folded)
|
||||
line, err = sock:receive()
|
||||
@ -62,7 +62,7 @@ local function receiveheaders(sock, headers)
|
||||
-- unfold any folded values
|
||||
while string.find(line, "^%s") do
|
||||
value = value .. line
|
||||
line = sock:receive()
|
||||
line, err = sock:receive()
|
||||
if err then return nil, err end
|
||||
end
|
||||
-- save pair in table
|
||||
@ -81,7 +81,7 @@ socket.sourcet["http-chunked"] = function(sock, headers)
|
||||
dirty = function() return sock:dirty() end
|
||||
}, {
|
||||
__call = function()
|
||||
-- get chunk size, skip extention
|
||||
-- get chunk size, skip extension
|
||||
local line, err = sock:receive()
|
||||
if err then return nil, err end
|
||||
local size = base.tonumber(string.gsub(line, ";.*", ""), 16)
|
||||
@ -207,7 +207,6 @@ local function adjusturi(reqt)
|
||||
if not reqt.proxy and not _M.PROXY then
|
||||
u = {
|
||||
path = socket.try(reqt.path, "invalid path 'nil'"),
|
||||
params = reqt.params,
|
||||
query = reqt.query,
|
||||
fragment = reqt.fragment
|
||||
}
|
||||
@ -219,9 +218,11 @@ local function adjustproxy(reqt)
|
||||
local proxy = reqt.proxy or _M.PROXY
|
||||
if proxy then
|
||||
proxy = url.parse(proxy)
|
||||
return proxy.host, proxy.port or 3128
|
||||
proxy.port = proxy.port or 3128
|
||||
proxy.create = SCHEMES[proxy.scheme].create(reqt)
|
||||
return proxy.host, proxy.port, proxy.create
|
||||
else
|
||||
return reqt.host, reqt.port
|
||||
return reqt.host, reqt.port, reqt.create
|
||||
end
|
||||
end
|
||||
|
||||
@ -279,7 +280,7 @@ local function adjustrequest(reqt)
|
||||
if not (host and host ~= "") then
|
||||
socket.try(nil, "invalid host '" .. base.tostring(nreqt.host) .. "'")
|
||||
end
|
||||
-- compute uri if user hasn't overriden
|
||||
-- compute uri if user hasn't overridden
|
||||
nreqt.uri = reqt.uri or adjusturi(nreqt)
|
||||
-- adjust headers in request
|
||||
nreqt.headers = adjustheaders(nreqt)
|
||||
@ -291,7 +292,10 @@ local function adjustrequest(reqt)
|
||||
end
|
||||
|
||||
-- ajust host and port if there is a proxy
|
||||
nreqt.host, nreqt.port = adjustproxy(nreqt)
|
||||
local proxy_create
|
||||
nreqt.host, nreqt.port, proxy_create = adjustproxy(nreqt)
|
||||
if not reqt.create then nreqt.create = proxy_create end
|
||||
|
||||
return nreqt
|
||||
end
|
||||
|
||||
|
@ -290,7 +290,7 @@ int inet_meth_getsockname(lua_State *L, p_socket ps, int family)
|
||||
return 2;
|
||||
}
|
||||
lua_pushstring(L, name);
|
||||
lua_pushstring(L, port);
|
||||
lua_pushinteger(L, (int) strtol(port, (char **) NULL, 10));
|
||||
switch (family) {
|
||||
case AF_INET: lua_pushliteral(L, "inet"); break;
|
||||
case AF_INET6: lua_pushliteral(L, "inet6"); break;
|
||||
|
@ -10,7 +10,7 @@
|
||||
/*-------------------------------------------------------------------------* \
|
||||
* Current socket library version
|
||||
\*-------------------------------------------------------------------------*/
|
||||
#define LUASOCKET_VERSION "LuaSocket 3.0.0"
|
||||
#define LUASOCKET_VERSION "LuaSocket 3.1.0"
|
||||
#define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2013 Diego Nehab"
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
|
@ -1,6 +1,6 @@
|
||||
# luasocket src/makefile
|
||||
#
|
||||
# Definitions in this section can be overriden on the command line or in the
|
||||
# Definitions in this section can be overridden on the command line or in the
|
||||
# environment.
|
||||
#
|
||||
# These are equivalent:
|
||||
@ -272,7 +272,7 @@ SOCKET_win64=wsocket.obj
|
||||
#
|
||||
SO=$(SO_$(PLAT))
|
||||
O=$(O_$(PLAT))
|
||||
SOCKET_V=3.0.0
|
||||
SOCKET_V=3.1.0
|
||||
MIME_V=1.0.3
|
||||
SOCKET_SO=socket-$(SOCKET_V).$(SO)
|
||||
MIME_SO=mime-$(MIME_V).$(SO)
|
||||
|
@ -225,7 +225,7 @@ local function adjust_headers(mesgt)
|
||||
lower["date"] = lower["date"] or
|
||||
os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or _M.ZONE)
|
||||
lower["x-mailer"] = lower["x-mailer"] or socket._VERSION
|
||||
-- this can't be overriden
|
||||
-- this can't be overridden
|
||||
lower["mime-version"] = "1.0"
|
||||
return lower
|
||||
end
|
||||
|
19
src/url.lua
19
src/url.lua
@ -125,7 +125,7 @@ end
|
||||
-----------------------------------------------------------------------------
|
||||
-- Parses a url and returns a table with all its parts according to RFC 2396
|
||||
-- The following grammar describes the names given to the URL parts
|
||||
-- <url> ::= <scheme>://<authority>/<path>;<params>?<query>#<fragment>
|
||||
-- <url> ::= <scheme>://<authority>/<path>?<query>#<fragment>
|
||||
-- <authority> ::= <userinfo>@<host>:<port>
|
||||
-- <userinfo> ::= <user>[:<password>]
|
||||
-- <path> :: = {<segment>/}<segment>
|
||||
@ -136,7 +136,7 @@ end
|
||||
-- table with the following fields, where RFC naming conventions have
|
||||
-- been preserved:
|
||||
-- scheme, authority, userinfo, user, password, host, port,
|
||||
-- path, params, query, fragment
|
||||
-- path, query, fragment
|
||||
-- Obs:
|
||||
-- the leading '/' in {/<path>} is considered part of <path>
|
||||
-----------------------------------------------------------------------------
|
||||
@ -152,7 +152,7 @@ function _M.parse(url, default)
|
||||
url = string.gsub(url, "^([%w][%w%+%-%.]*)%:",
|
||||
function(s) parsed.scheme = s; return "" end)
|
||||
-- get authority
|
||||
url = string.gsub(url, "^//([^/]*)", function(n)
|
||||
url = string.gsub(url, "^//([^/%?#]*)", function(n)
|
||||
parsed.authority = n
|
||||
return ""
|
||||
end)
|
||||
@ -166,11 +166,6 @@ function _M.parse(url, default)
|
||||
parsed.query = q
|
||||
return ""
|
||||
end)
|
||||
-- get params
|
||||
url = string.gsub(url, "%;(.*)", function(p)
|
||||
parsed.params = p
|
||||
return ""
|
||||
end)
|
||||
-- path is whatever was left
|
||||
if url ~= "" then parsed.path = url end
|
||||
local authority = parsed.authority
|
||||
@ -203,7 +198,6 @@ function _M.build(parsed)
|
||||
--local ppath = _M.parse_path(parsed.path or "")
|
||||
--local url = _M.build_path(ppath)
|
||||
local url = parsed.path or ""
|
||||
if parsed.params then url = url .. ";" .. parsed.params end
|
||||
if parsed.query then url = url .. "?" .. parsed.query end
|
||||
local authority = parsed.authority
|
||||
if parsed.host then
|
||||
@ -258,11 +252,8 @@ function _M.absolute(base_url, relative_url)
|
||||
relative_parsed.authority = base_parsed.authority
|
||||
if not relative_parsed.path then
|
||||
relative_parsed.path = base_parsed.path
|
||||
if not relative_parsed.params then
|
||||
relative_parsed.params = base_parsed.params
|
||||
if not relative_parsed.query then
|
||||
relative_parsed.query = base_parsed.query
|
||||
end
|
||||
if not relative_parsed.query then
|
||||
relative_parsed.query = base_parsed.query
|
||||
end
|
||||
else
|
||||
relative_parsed.path = absolute_path(base_parsed.path or "",
|
||||
|
@ -262,6 +262,7 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got,
|
||||
if (err != WSAEWOULDBLOCK) {
|
||||
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
|
||||
prev = err;
|
||||
continue;
|
||||
}
|
||||
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
||||
}
|
||||
@ -291,6 +292,7 @@ int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
|
||||
if (err != WSAEWOULDBLOCK) {
|
||||
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
|
||||
prev = err;
|
||||
continue;
|
||||
}
|
||||
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
||||
}
|
||||
|
@ -99,8 +99,7 @@ check_parse_url{
|
||||
userinfo = "user:pass$%?#wd",
|
||||
password = "pass$%?#wd",
|
||||
user = "user",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -113,8 +112,7 @@ check_parse_url{
|
||||
userinfo = "user:pass?#wd",
|
||||
password = "pass?#wd",
|
||||
user = "user",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -127,8 +125,7 @@ check_parse_url{
|
||||
userinfo = "user:pass-wd",
|
||||
password = "pass-wd",
|
||||
user = "user",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -141,8 +138,7 @@ check_parse_url{
|
||||
userinfo = "user:pass#wd",
|
||||
password = "pass#wd",
|
||||
user = "user",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -155,8 +151,7 @@ check_parse_url{
|
||||
userinfo = "user:pass#wd",
|
||||
password = "pass#wd",
|
||||
user = "user",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
}
|
||||
check_parse_url{
|
||||
@ -167,8 +162,7 @@ check_parse_url{
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
user = "userinfo",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -182,8 +176,7 @@ check_parse_url{
|
||||
userinfo = "user:password",
|
||||
user = "user",
|
||||
password = "password",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment",
|
||||
}
|
||||
@ -196,8 +189,7 @@ check_parse_url{
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
user = "userinfo",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = ""
|
||||
}
|
||||
@ -210,8 +202,7 @@ check_parse_url{
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
user = "userinfo",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -224,8 +215,7 @@ check_parse_url{
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
user = "userinfo",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
fragment = "fragment"
|
||||
}
|
||||
|
||||
@ -237,8 +227,7 @@ check_parse_url{
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
user = "userinfo",
|
||||
path = "/path",
|
||||
params = "",
|
||||
path = "/path;",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -264,8 +253,7 @@ check_parse_url{
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
user = "userinfo",
|
||||
path = "/",
|
||||
params = "params",
|
||||
path = "/;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -287,8 +275,7 @@ check_parse_url{
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
user = "userinfo",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -438,8 +425,7 @@ check_parse_url{
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
user = "userinfo",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -453,8 +439,7 @@ check_parse_url{
|
||||
userinfo = "user:password",
|
||||
user = "user",
|
||||
password = "password",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -467,8 +452,7 @@ check_build_url {
|
||||
port = "port",
|
||||
user = "user",
|
||||
password = "password",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -478,8 +462,7 @@ check_build_url{
|
||||
host = "::FFFF:129.144.52.38",
|
||||
port = "port",
|
||||
user = "userinfo",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -491,8 +474,7 @@ check_build_url{
|
||||
port = "port",
|
||||
user = "user",
|
||||
password = "password",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -503,8 +485,7 @@ check_build_url {
|
||||
host = "host",
|
||||
user = "user",
|
||||
password = "password",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -514,8 +495,7 @@ check_build_url {
|
||||
scheme = "scheme",
|
||||
host = "host",
|
||||
user = "user",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -524,8 +504,7 @@ check_build_url {
|
||||
url = "scheme://host/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
host = "host",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -534,8 +513,7 @@ check_build_url {
|
||||
url = "scheme://host/path;params#fragment",
|
||||
scheme = "scheme",
|
||||
host = "host",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
fragment = "fragment"
|
||||
}
|
||||
|
||||
@ -573,9 +551,7 @@ check_build_url {
|
||||
user = "user",
|
||||
userinfo = "not used",
|
||||
password = "password",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
query = "query",
|
||||
path = "/path;params",
|
||||
fragment = "fragment"
|
||||
}
|
||||
|
||||
@ -588,8 +564,7 @@ check_build_url {
|
||||
userinfo = "not used",
|
||||
authority = "not used",
|
||||
password = "password",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -601,8 +576,7 @@ check_build_url {
|
||||
port = "port",
|
||||
userinfo = "user:password",
|
||||
authority = "not used",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
@ -611,8 +585,7 @@ check_build_url {
|
||||
url = "scheme://user:password@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "user:password@host:port",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
path = "/path;params",
|
||||
query = "query",
|
||||
fragment = "fragment"
|
||||
}
|
||||
|
Reference in New Issue
Block a user