From 87ea9c6efd74bb00034d057aa0ed50d9ebd2b7ed Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 26 Aug 2018 21:38:04 +1000 Subject: [PATCH 1/5] http/headers.tld: Fix bad syntax --- http/headers.tld | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http/headers.tld b/http/headers.tld index 63d91e94..72ba9491 100644 --- a/http/headers.tld +++ b/http/headers.tld @@ -1,5 +1,5 @@ interface headers - const clone : (self) -> headers + const clone : (self) -> (headers) const append : (self, string, string, nil|boolean) -> () const each : (self) -> ((self) -> (string, string, boolean)) const has : (self, string) -> (boolean) From 97770a057d2f824ace8526fe4fafc16e161cbab8 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 26 Aug 2018 22:08:59 +1000 Subject: [PATCH 2/5] http/headers.tld: Remove extra whitespace --- http/headers.tld | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/http/headers.tld b/http/headers.tld index 72ba9491..3b242e06 100644 --- a/http/headers.tld +++ b/http/headers.tld @@ -1,17 +1,17 @@ interface headers - const clone : (self) -> (headers) - const append : (self, string, string, nil|boolean) -> () - const each : (self) -> ((self) -> (string, string, boolean)) - const has : (self, string) -> (boolean) - const delete : (self, string) -> (boolean) - const geti : (self, integer) -> (string, string, boolean) - const get_as_sequence : (self, string) -> ({"n": integer, integer:string}) - const get : (self, string) -> (string*) - const get_comma_separated : (self, string) -> (string|nil) - const modifyi : (self, integer, string, boolean?) -> () - const upsert : (self, string, string, boolean?) -> () - const sort : (self) -> () - const dump : (self, nil|file, nil|string) -> () + const clone: (self) -> (headers) + const append: (self, string, string, nil|boolean) -> () + const each: (self) -> ((self) -> (string, string, boolean)) + const has: (self, string) -> (boolean) + const delete: (self, string) -> (boolean) + const geti: (self, integer) -> (string, string, boolean) + const get_as_sequence: (self, string) -> ({"n": integer, integer:string}) + const get: (self, string) -> (string*) + const get_comma_separated: (self, string) -> (string|nil) + const modifyi: (self, integer, string, boolean?) -> () + const upsert: (self, string, string, boolean?) -> () + const sort: (self) -> () + const dump: (self, nil|file, nil|string) -> () end new : () -> (headers) From e3937902b32ee5a43e4b311436d9aece1885f2ca Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 26 Aug 2018 23:40:31 +1000 Subject: [PATCH 3/5] http/headers.tld: Use '?' form --- http/headers.tld | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/http/headers.tld b/http/headers.tld index 3b242e06..92fb430e 100644 --- a/http/headers.tld +++ b/http/headers.tld @@ -1,6 +1,6 @@ interface headers const clone: (self) -> (headers) - const append: (self, string, string, nil|boolean) -> () + const append: (self, string, string, boolean?) -> () const each: (self) -> ((self) -> (string, string, boolean)) const has: (self, string) -> (boolean) const delete: (self, string) -> (boolean) @@ -11,7 +11,7 @@ interface headers const modifyi: (self, integer, string, boolean?) -> () const upsert: (self, string, string, boolean?) -> () const sort: (self) -> () - const dump: (self, nil|file, nil|string) -> () + const dump: (self, file?, string?) -> () end new : () -> (headers) From 9dbabceba1a2c7a989360b7fdf4be241849d8445 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 26 Aug 2018 21:45:51 +1000 Subject: [PATCH 4/5] Add typedlua defintions for more modules --- http/bit.tld | 3 +++ http/connection_common.tld | 19 +++++++++++++++++++ http/cookie.tld | 28 ++++++++++++++++++++++++++++ http/h1_reason_phrases.tld | 1 + http/h2_error.tld | 15 +++++++++++++++ http/hsts.tld | 13 +++++++++++++ http/proxies.tld | 6 ++++++ http/request.tld | 26 ++++++++++++++++++++++++++ http/stream_common.tld | 22 ++++++++++++++++++++++ http/tls.tld | 9 +++++++++ http/util.tld | 15 +++++++++++++++ http/version.tld | 2 ++ http/zlib.tld | 2 ++ 13 files changed, 161 insertions(+) create mode 100644 http/bit.tld create mode 100644 http/connection_common.tld create mode 100644 http/cookie.tld create mode 100644 http/h1_reason_phrases.tld create mode 100644 http/h2_error.tld create mode 100644 http/hsts.tld create mode 100644 http/proxies.tld create mode 100644 http/request.tld create mode 100644 http/stream_common.tld create mode 100644 http/tls.tld create mode 100644 http/util.tld create mode 100644 http/version.tld create mode 100644 http/zlib.tld diff --git a/http/bit.tld b/http/bit.tld new file mode 100644 index 00000000..886b0b24 --- /dev/null +++ b/http/bit.tld @@ -0,0 +1,3 @@ +band: (integer, integer) -> (integer) +bor: (integer, integer) -> (integer) +bxor: (integer, integer) -> (integer) diff --git a/http/connection_common.tld b/http/connection_common.tld new file mode 100644 index 00000000..5e008daf --- /dev/null +++ b/http/connection_common.tld @@ -0,0 +1,19 @@ +interface connection + -- implements cqueues polling interface + const pollfd: (self) -> (nil)|(integer) -- TODO: cqueues condition + const events: (self) -> (nil)|(string|integer) + const timeout: (self) -> (nil)|(number) + + const checktls: (self) -> (nil)|(any) -- TODO: luaossl SSL object + const localname: (self) -> (integer, string, integer?)|(nil)|(nil, string, number) + const peername: (self) -> (integer, string, integer?)|(nil)|(nil, string, number) + const onidle: (self, (connection)->()) -> ((connection)->()) + const connect: (self) -> (true)|(nil)|(nil, string, number) + const flush: (self, number) -> (true)|(nil, string, number) + const close: (self) -> (true) + + -- Not in connection_common.lua + const version: integer + const unget: (self, string) -> (true) + const shutdown: (self) -> (true) +end diff --git a/http/cookie.tld b/http/cookie.tld new file mode 100644 index 00000000..55eaf244 --- /dev/null +++ b/http/cookie.tld @@ -0,0 +1,28 @@ +require "http.headers" + +bake: (string, string, number?, string?, string?, true?, true?, string?) -> (string) + +parse_cookie: (string) -> ({string:string}) +parse_cookies: (headers) -> ({{string:string}}) +parse_setcookie: (string) -> (string, string, {string:string}) + +interface cookie_store + psl: any|false -- TODO: use psl type + time: () -> (number) + max_cookie_length: number + max_cookies: number + max_cookies_per_domain: number + + const store: (self, string, string, boolean, boolean, string?, string, string, {string:string}) -> (boolean) + const store_from_request: (self, headers, headers, string, string?) -> (boolean) + const get: (self, string, string, string) -> (string) + const remove: (self, string, string?, string?) -> () + const lookup: (self, string, string, boolean?, boolean?, boolean?, string?, boolean?, integer?) -> () + const lookup_for_request: (self, headers, string, string?, boolean?, integer?) -> () + const clean_due: (self) -> (number) + const clean: (self) -> (boolean) + const load_from_file: (self, file) -> (true) | (nil, string, integer) + const save_to_file: (self, file) -> (true) | (nil, string, integer) +end + +new_store: () -> (cookie_store) diff --git a/http/h1_reason_phrases.tld b/http/h1_reason_phrases.tld new file mode 100644 index 00000000..ee584054 --- /dev/null +++ b/http/h1_reason_phrases.tld @@ -0,0 +1 @@ +reason_phrases: {string:string} diff --git a/http/h2_error.tld b/http/h2_error.tld new file mode 100644 index 00000000..78883dcd --- /dev/null +++ b/http/h2_error.tld @@ -0,0 +1,15 @@ +interface h2_error + const new: (self, { + "name": string?, + "code": integer?, + "description": string?, + "message": string?, + "traceback": string?, + "stream_error": boolean? + }) -> (h2_error) + const new_traceback: (self, string, boolean, integer?) -> (h2_error) + const error: (self, string, boolean, integer?) -> (void) +end + +errors: {any:h2_error} +is: (any) -> (boolean) diff --git a/http/hsts.tld b/http/hsts.tld new file mode 100644 index 00000000..952aab4c --- /dev/null +++ b/http/hsts.tld @@ -0,0 +1,13 @@ +interface hsts_store + time: () -> (number) + max_items: number + + clone: (self) -> (hsts_store) + store: (self, string, {string:string}) -> (boolean) + remove: (self, string) -> (boolean) + check: (self, hsts_store) -> (boolean) + const clean_due: (self) -> (number) + const clean: (self) -> (boolean) +end + +new_store: () -> (hsts_store) diff --git a/http/proxies.tld b/http/proxies.tld new file mode 100644 index 00000000..f73d539c --- /dev/null +++ b/http/proxies.tld @@ -0,0 +1,6 @@ +interface proxies + const update: (self, (string)->(string?))->(self) + const choose: (self, string, string)->(string?) +end + +new: proxies diff --git a/http/request.tld b/http/request.tld new file mode 100644 index 00000000..bbe50c2f --- /dev/null +++ b/http/request.tld @@ -0,0 +1,26 @@ +require "http.cookie" +require "http.hsts" +require "http.proxies" +require "http.stream_common" + +interface request + hsts: hsts_store|false + proxies: proxies|false + cookie_store: cookie_store|false + is_top_level: boolean + site_for_cookies: string? + expect_100_timeout: integer + follow_redirects: boolean + max_redirects: integer + post301: boolean + post302: boolean + headers: headers + const clone: (self) -> (request) + const to_uri: (self, boolean?) -> (string) + const handle_redirect: (self, headers) -> (request)|(nil, string, integer) + const set_body: (self, string|file|()->(string?)) -> () + const go: (self, number) -> (headers, stream)|(nil, string, integer) +end + +new_from_uri: (string, headers?) -> (request) +new_connect: (string, string) -> (request) diff --git a/http/stream_common.tld b/http/stream_common.tld new file mode 100644 index 00000000..75be7709 --- /dev/null +++ b/http/stream_common.tld @@ -0,0 +1,22 @@ +require "http.connection_common" + +interface stream + const checktls: (self) -> (nil)|(any) + const localname: (self) -> (integer, string, integer?)|(nil)|(nil, string, number) + const peername: (self) -> (integer, string, integer?)|(nil)|(nil, string, number) + const write_continue: (self, number?) -> (true)|(nil, string, number) + const each_chunk: (self) -> () + const get_body_as_string: (self, number?) -> (string)|(nil, string, number) + const get_body_chars: (self, integer, number?) -> (string)|(nil, string, number) + const get_body_until: (self, string, boolean, boolean, number?) -> (string)|(nil, string, number) + const save_body_to_file: (self, file, number?) -> (true)|(nil, string, number) + const get_body_as_file: (self, number?) -> (file)|(nil, string, number) + const write_body_from_string: (self, string, number?) -> (true)|(nil, string, number) + const write_body_from_file: (self, {"file":file, "count": integer?}|file, number?) -> (true)|(nil, string, number) + -- Not in stream_common.lua + const connection: connection + const write_headers: (self, headers, boolean, number?) -> (true)|(nil, string, number) + const write_chunk: (self, string, boolean, number?) -> (true)|(nil, string, number) + const unget: (self, string) -> (true) + const shutdown: (self) -> (true) +end diff --git a/http/tls.tld b/http/tls.tld new file mode 100644 index 00000000..43b851e5 --- /dev/null +++ b/http/tls.tld @@ -0,0 +1,9 @@ +has_alpn: boolean +has_hostname_validation: boolean +modern_cipher_list: string +intermediate_cipher_list: string +old_cipher_list: string +banned_ciphers: {string: true} +-- TODO: luaossl SSL context type +new_client_context: any +new_server_context: any diff --git a/http/util.tld b/http/util.tld new file mode 100644 index 00000000..e23998f4 --- /dev/null +++ b/http/util.tld @@ -0,0 +1,15 @@ +encodeURI: (string) -> (string) +encodeURIComponent: (string) -> (string) +decodeURI: (string) -> (string) +decodeURIComponent: (string) -> (string) +query_args: (string) -> ((any) -> (string, string), any, any) +dict_to_query: ({string:string}) -> (string) +resolve_relative_path: (orig_path, relative_path) -> (string) +is_safe_method: (method) -> (boolean) +is_ip: (string) -> (boolean) +scheme_to_port: {string:integer} +split_authority: (string, string) -> (string, integer)|(nil, string) +to_authority: (string, integer, string|nil) -> (string) +imf_date: (time) -> (string) +maybe_quote: (string) -> (string) +yieldable_pcall: ((any*) -> (any*), any*) -> (boolean, any*) diff --git a/http/version.tld b/http/version.tld new file mode 100644 index 00000000..b0728b00 --- /dev/null +++ b/http/version.tld @@ -0,0 +1,2 @@ +name: string +version: string diff --git a/http/zlib.tld b/http/zlib.tld new file mode 100644 index 00000000..2470fd6e --- /dev/null +++ b/http/zlib.tld @@ -0,0 +1,2 @@ +inflate: () -> ((string, boolean) -> (string)) +deflate: () -> ((string, boolean) -> (string)) From 5762c00c39e22cdc2c05e85006c031944120b881 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 26 Aug 2018 23:41:54 +1000 Subject: [PATCH 5/5] .travis.yml: Lint .tld files --- .travis.yml | 2 ++ spec/require-all.lua | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 spec/require-all.lua diff --git a/.travis.yml b/.travis.yml index 423e9574..4e65d6d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,7 @@ before_install: - export PATH=$PATH:~/hererocks/bin - eval $(luarocks path --bin) - luarocks install luacheck + - luarocks install https://raw.githubusercontent.com/andremm/typedlua/master/typedlua-scm-1.rockspec - luarocks install luacov-coveralls - luarocks install busted @@ -46,6 +47,7 @@ install: script: - luacheck . + - tlc -o /dev/null spec/require-all.lua - busted -c after_success: diff --git a/spec/require-all.lua b/spec/require-all.lua new file mode 100644 index 00000000..7e963112 --- /dev/null +++ b/spec/require-all.lua @@ -0,0 +1,27 @@ +-- This file is used for linting .tld files with typedlua + +require "http.bit" +require "http.client" +require "http.connection_common" +require "http.cookie" +require "http.h1_connection" +require "http.h1_reason_phrases" +require "http.h1_stream" +require "http.h2_connection" +require "http.h2_error" +require "http.h2_stream" +require "http.headers" +require "http.hpack" +require "http.hsts" +require "http.proxies" +require "http.request" +require "http.server" +require "http.socks" +require "http.stream_common" +require "http.tls" +require "http.util" +require "http.version" +require "http.websocket" +require "http.zlib" +require "http.compat.prosody" +require "http.compat.socket"