{"action":"created","comment":{"url":"https://api.github.com/repos/daurnimator/lua-http/pulls/comments/91853917","pull_request_review_id":12365157,"id":91853917,"diff_hunk":"@@ -1032,68 +1050,153 @@ On success, returns the response [*headers*](#http.headers) and a [*stream*](#st\n \n ## http.server\n \n-This interface is **unstable**.\n+The http.server object is used to listen on sockets and respond to all types of HTTP requests. Each client request is threaded and independent of the other client requests. An `http.server` is instantiated by passing a number of options including an `onstream` response handler that processes the HTTP requests and provides a stream mechanism for response. `onstream` can also be used for testing and upgrading a request, with HTTP 1.1 to WebSockets being the notible example. The server can be made non-blocking when used in conjunction with cqueues. \n+\n+### `server.listen(options)` <!-- --> {#http.server.listen}\n+\n+Create a new instance of an HTTP Server by passing in table `options`:\n+\n+  - `.client_timeout`: Timeout (in seconds) to wait for client to send first bytes and/or complete TLS handshake (default: 10)\n+  - `.cq` (optional): A cqueues controller to use\n+  - `.ctx`: An `openssl.ssl.context` object to use for tls connections. If `nil` is passed, a self-signed context will be generated\n+  - `.family`: (optional) Protocol family\n+  - `.host`: Address to bind to (required if not `.path`)\n+  - `.port`: Port to bind to (optional if tls isn't `nil`, in which case defaults to 80 for `.tls == false` or 443 if `.tls == true`)\n+  - `.path`: Path to UNIX socket (required if not `.host`)\n+  - `.v6only`: Allow ipv6 only (no ipv4-mapped-ipv6)\n+  - `.mode`: (optional) `fchmod` or `chmod` socket after creating UNIX domain socket\n+  - `.mask`: (optional) Set and restore umask when binding UNIX domain socket\n+  - `.unlink`: (optional) Unlink socket path before binding\n+  - `.max_concurrent`: Maximum number of connections to allow live at a time (default: infinity)\n+  - `.onerror`: Function that will be called when an error occurs (default: do nothing). See [server:onerror()](#http.server:onerror)\n+  - `.onstream`: Callback function for handling a new client request. The function requires parameters for [*server*](#http.server) and [*stream*](#stream) and if your function throws an error it will be reported from [*step*](#http.server:step) or [*loop*](#http.server:loop)\n+  - `.reuseaddr`: (optional) Turn on SO_REUSEADDR flag\n+  - `.reuseport`: (optional) Turn on SO_REUSEPORT flag\n+  - `.tls`: `nil`: Allow both tls and non-tls connections\n+  -         `true`: Allows tls connections only\n+  -         `false`: Allows non-tls connections only\n+  - `.version`: The http version to allow to connect (default: any)\n+\n+\n+#### Example {#http.server.listen-example}\n \n-### `listen(options)` <!-- --> {#http.server.connect}\n+```lua\n+\n+local app_server = http_server.listen {\n+\t\thost = 192.168.0.1;\n+\t\tport = 80;\n+\t\tonstream = function(server, stream)  \n+\t\t\tlocal request_headers = assert(stream:get_headers())\n+\t\t\tlocal request_method = request_headers:get \":method\"\n+\n+\t\t\tprint(string.format('[%s] \"%s %s HTTP/%g\"  \"%s\" \"%s\" ',\n+\t\t\t\tos.date(\"%d/%b/%Y:%H:%M:%S %z\"),\n+\t\t\t\trequest_headers:get(\":method\") or \"\",\n+\t\t\t\trequest_headers:get(\":path\") or \"\",\n+\t\t\t\tstream.connection.version,\n+\t\t\t\trequest_headers:get(\"referer\") or \"-\",\n+\t\t\t\trequest_headers:get(\"user-agent\") or \"-\"\n+\t\t\t\t))\n+\t\tend;\n+}\n+\n+```\n \n \n ### `server:onerror(new_handler)` <!-- --> {#http.server:onerror}\n \n+If called with parameters, the function replaces the current error handler function with `new_handler`  and returns a reference to the old function. Calling the function with no parameters returns the current error handler. The default error handler is to do nothing, and can be set during instantiation through the `options` table passed to the [*server.listen(options)*](#server.listen) function.","path":"doc/index.md","position":134,"original_position":126,"commit_id":"0e2df19d810a7bf92d33ea27d071d1872e8eb431","original_commit_id":"7873c71aa6886e6ac94827e19610d37c65f6fd6c","user":{"login":"daurnimator","id":127971,"avatar_url":"https://avatars.githubusercontent.com/u/127971?v=3","gravatar_id":"","url":"https://api.github.com/users/daurnimator","html_url":"https://github.com/daurnimator","followers_url":"https://api.github.com/users/daurnimator/followers","following_url":"https://api.github.com/users/daurnimator/following{/other_user}","gists_url":"https://api.github.com/users/daurnimator/gists{/gist_id}","starred_url":"https://api.github.com/users/daurnimator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daurnimator/subscriptions","organizations_url":"https://api.github.com/users/daurnimator/orgs","repos_url":"https://api.github.com/users/daurnimator/repos","events_url":"https://api.github.com/users/daurnimator/events{/privacy}","received_events_url":"https://api.github.com/users/daurnimator/received_events","type":"User","site_admin":false},"body":"That was quite a while ago. See master now: https://github.com/daurnimator/lua-http/blob/3f1bf0dd5fd1f930a222c2cfabf8d28a652f5619/http/server.lua#L388","created_at":"2016-12-11T11:35:00Z","updated_at":"2016-12-11T11:35:00Z","html_url":"https://github.com/daurnimator/lua-http/pull/58#discussion_r91853917","pull_request_url":"https://api.github.com/repos/daurnimator/lua-http/pulls/58","_links":{"self":{"href":"https://api.github.com/repos/daurnimator/lua-http/pulls/comments/91853917"},"html":{"href":"https://github.com/daurnimator/lua-http/pull/58#discussion_r91853917"},"pull_request":{"href":"https://api.github.com/repos/daurnimator/lua-http/pulls/58"}}},"pull_request":{"url":"https://api.github.com/repos/daurnimator/lua-http/pulls/58","id":94311042,"html_url":"https://github.com/daurnimator/lua-http/pull/58","diff_url":"https://github.com/daurnimator/lua-http/pull/58.diff","patch_url":"https://github.com/daurnimator/lua-http/pull/58.patch","issue_url":"https://api.github.com/repos/daurnimator/lua-http/issues/58","number":58,"state":"open","locked":false,"title":"Reworked introduction.","user":{"login":"RussellHaley","id":2166039,"avatar_url":"https://avatars.githubusercontent.com/u/2166039?v=3","gravatar_id":"","url":"https://api.github.com/users/RussellHaley","html_url":"https://github.com/RussellHaley","followers_url":"https://api.github.com/users/RussellHaley/followers","following_url":"https://api.github.com/users/RussellHaley/following{/other_user}","gists_url":"https://api.github.com/users/RussellHaley/gists{/gist_id}","starred_url":"https://api.github.com/users/RussellHaley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RussellHaley/subscriptions","organizations_url":"https://api.github.com/users/RussellHaley/orgs","repos_url":"https://api.github.com/users/RussellHaley/repos","events_url":"https://api.github.com/users/RussellHaley/events{/privacy}","received_events_url":"https://api.github.com/users/RussellHaley/received_events","type":"User","site_admin":false},"body":"Removed some of the busy-ness and added white space using headers.","created_at":"2016-11-18T06:47:03Z","updated_at":"2016-12-11T11:35:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/daurnimator/lua-http/pulls/58/commits","review_comments_url":"https://api.github.com/repos/daurnimator/lua-http/pulls/58/comments","review_comment_url":"https://api.github.com/repos/daurnimator/lua-http/pulls/comments{/number}","comments_url":"https://api.github.com/repos/daurnimator/lua-http/issues/58/comments","statuses_url":"https://api.github.com/repos/daurnimator/lua-http/statuses/0e2df19d810a7bf92d33ea27d071d1872e8eb431","head":{"label":"RussellHaley:master","ref":"master","sha":"0e2df19d810a7bf92d33ea27d071d1872e8eb431","user":{"login":"RussellHaley","id":2166039,"avatar_url":"https://avatars.githubusercontent.com/u/2166039?v=3","gravatar_id":"","url":"https://api.github.com/users/RussellHaley","html_url":"https://github.com/RussellHaley","followers_url":"https://api.github.com/users/RussellHaley/followers","following_url":"https://api.github.com/users/RussellHaley/following{/other_user}","gists_url":"https://api.github.com/users/RussellHaley/gists{/gist_id}","starred_url":"https://api.github.com/users/RussellHaley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RussellHaley/subscriptions","organizations_url":"https://api.github.com/users/RussellHaley/orgs","repos_url":"https://api.github.com/users/RussellHaley/repos","events_url":"https://api.github.com/users/RussellHaley/events{/privacy}","received_events_url":"https://api.github.com/users/RussellHaley/received_events","type":"User","site_admin":false},"repo":{"id":72906723,"name":"lua-http","full_name":"RussellHaley/lua-http","owner":{"login":"RussellHaley","id":2166039,"avatar_url":"https://avatars.githubusercontent.com/u/2166039?v=3","gravatar_id":"","url":"https://api.github.com/users/RussellHaley","html_url":"https://github.com/RussellHaley","followers_url":"https://api.github.com/users/RussellHaley/followers","following_url":"https://api.github.com/users/RussellHaley/following{/other_user}","gists_url":"https://api.github.com/users/RussellHaley/gists{/gist_id}","starred_url":"https://api.github.com/users/RussellHaley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RussellHaley/subscriptions","organizations_url":"https://api.github.com/users/RussellHaley/orgs","repos_url":"https://api.github.com/users/RussellHaley/repos","events_url":"https://api.github.com/users/RussellHaley/events{/privacy}","received_events_url":"https://api.github.com/users/RussellHaley/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/RussellHaley/lua-http","description":"HTTP Library for Lua. Supports HTTP(S) 1.0, 1.1 and 2.0; client and server.","fork":true,"url":"https://api.github.com/repos/RussellHaley/lua-http","forks_url":"https://api.github.com/repos/RussellHaley/lua-http/forks","keys_url":"https://api.github.com/repos/RussellHaley/lua-http/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RussellHaley/lua-http/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RussellHaley/lua-http/teams","hooks_url":"https://api.github.com/repos/RussellHaley/lua-http/hooks","issue_events_url":"https://api.github.com/repos/RussellHaley/lua-http/issues/events{/number}","events_url":"https://api.github.com/repos/RussellHaley/lua-http/events","assignees_url":"https://api.github.com/repos/RussellHaley/lua-http/assignees{/user}","branches_url":"https://api.github.com/repos/RussellHaley/lua-http/branches{/branch}","tags_url":"https://api.github.com/repos/RussellHaley/lua-http/tags","blobs_url":"https://api.github.com/repos/RussellHaley/lua-http/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RussellHaley/lua-http/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RussellHaley/lua-http/git/refs{/sha}","trees_url":"https://api.github.com/repos/RussellHaley/lua-http/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RussellHaley/lua-http/statuses/{sha}","languages_url":"https://api.github.com/repos/RussellHaley/lua-http/languages","stargazers_url":"https://api.github.com/repos/RussellHaley/lua-http/stargazers","contributors_url":"https://api.github.com/repos/RussellHaley/lua-http/contributors","subscribers_url":"https://api.github.com/repos/RussellHaley/lua-http/subscribers","subscription_url":"https://api.github.com/repos/RussellHaley/lua-http/subscription","commits_url":"https://api.github.com/repos/RussellHaley/lua-http/commits{/sha}","git_commits_url":"https://api.github.com/repos/RussellHaley/lua-http/git/commits{/sha}","comments_url":"https://api.github.com/repos/RussellHaley/lua-http/comments{/number}","issue_comment_url":"https://api.github.com/repos/RussellHaley/lua-http/issues/comments{/number}","contents_url":"https://api.github.com/repos/RussellHaley/lua-http/contents/{+path}","compare_url":"https://api.github.com/repos/RussellHaley/lua-http/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RussellHaley/lua-http/merges","archive_url":"https://api.github.com/repos/RussellHaley/lua-http/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RussellHaley/lua-http/downloads","issues_url":"https://api.github.com/repos/RussellHaley/lua-http/issues{/number}","pulls_url":"https://api.github.com/repos/RussellHaley/lua-http/pulls{/number}","milestones_url":"https://api.github.com/repos/RussellHaley/lua-http/milestones{/number}","notifications_url":"https://api.github.com/repos/RussellHaley/lua-http/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RussellHaley/lua-http/labels{/name}","releases_url":"https://api.github.com/repos/RussellHaley/lua-http/releases{/id}","deployments_url":"https://api.github.com/repos/RussellHaley/lua-http/deployments","created_at":"2016-11-05T05:17:37Z","updated_at":"2016-11-06T17:47:38Z","pushed_at":"2016-12-02T07:33:34Z","git_url":"git://github.com/RussellHaley/lua-http.git","ssh_url":"git@github.com:RussellHaley/lua-http.git","clone_url":"https://github.com/RussellHaley/lua-http.git","svn_url":"https://github.com/RussellHaley/lua-http","homepage":"","size":1071,"stargazers_count":0,"watchers_count":0,"language":"Lua","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"daurnimator:master","ref":"master","sha":"ea8f888ef7bd62112a6e885c24774914cf148ef8","user":{"login":"daurnimator","id":127971,"avatar_url":"https://avatars.githubusercontent.com/u/127971?v=3","gravatar_id":"","url":"https://api.github.com/users/daurnimator","html_url":"https://github.com/daurnimator","followers_url":"https://api.github.com/users/daurnimator/followers","following_url":"https://api.github.com/users/daurnimator/following{/other_user}","gists_url":"https://api.github.com/users/daurnimator/gists{/gist_id}","starred_url":"https://api.github.com/users/daurnimator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daurnimator/subscriptions","organizations_url":"https://api.github.com/users/daurnimator/orgs","repos_url":"https://api.github.com/users/daurnimator/repos","events_url":"https://api.github.com/users/daurnimator/events{/privacy}","received_events_url":"https://api.github.com/users/daurnimator/received_events","type":"User","site_admin":false},"repo":{"id":29999057,"name":"lua-http","full_name":"daurnimator/lua-http","owner":{"login":"daurnimator","id":127971,"avatar_url":"https://avatars.githubusercontent.com/u/127971?v=3","gravatar_id":"","url":"https://api.github.com/users/daurnimator","html_url":"https://github.com/daurnimator","followers_url":"https://api.github.com/users/daurnimator/followers","following_url":"https://api.github.com/users/daurnimator/following{/other_user}","gists_url":"https://api.github.com/users/daurnimator/gists{/gist_id}","starred_url":"https://api.github.com/users/daurnimator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daurnimator/subscriptions","organizations_url":"https://api.github.com/users/daurnimator/orgs","repos_url":"https://api.github.com/users/daurnimator/repos","events_url":"https://api.github.com/users/daurnimator/events{/privacy}","received_events_url":"https://api.github.com/users/daurnimator/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/daurnimator/lua-http","description":"HTTP Library for Lua. Supports HTTP(S) 1.0, 1.1 and 2.0; client and server.","fork":false,"url":"https://api.github.com/repos/daurnimator/lua-http","forks_url":"https://api.github.com/repos/daurnimator/lua-http/forks","keys_url":"https://api.github.com/repos/daurnimator/lua-http/keys{/key_id}","collaborators_url":"https://api.github.com/repos/daurnimator/lua-http/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/daurnimator/lua-http/teams","hooks_url":"https://api.github.com/repos/daurnimator/lua-http/hooks","issue_events_url":"https://api.github.com/repos/daurnimator/lua-http/issues/events{/number}","events_url":"https://api.github.com/repos/daurnimator/lua-http/events","assignees_url":"https://api.github.com/repos/daurnimator/lua-http/assignees{/user}","branches_url":"https://api.github.com/repos/daurnimator/lua-http/branches{/branch}","tags_url":"https://api.github.com/repos/daurnimator/lua-http/tags","blobs_url":"https://api.github.com/repos/daurnimator/lua-http/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/daurnimator/lua-http/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/daurnimator/lua-http/git/refs{/sha}","trees_url":"https://api.github.com/repos/daurnimator/lua-http/git/trees{/sha}","statuses_url":"https://api.github.com/repos/daurnimator/lua-http/statuses/{sha}","languages_url":"https://api.github.com/repos/daurnimator/lua-http/languages","stargazers_url":"https://api.github.com/repos/daurnimator/lua-http/stargazers","contributors_url":"https://api.github.com/repos/daurnimator/lua-http/contributors","subscribers_url":"https://api.github.com/repos/daurnimator/lua-http/subscribers","subscription_url":"https://api.github.com/repos/daurnimator/lua-http/subscription","commits_url":"https://api.github.com/repos/daurnimator/lua-http/commits{/sha}","git_commits_url":"https://api.github.com/repos/daurnimator/lua-http/git/commits{/sha}","comments_url":"https://api.github.com/repos/daurnimator/lua-http/comments{/number}","issue_comment_url":"https://api.github.com/repos/daurnimator/lua-http/issues/comments{/number}","contents_url":"https://api.github.com/repos/daurnimator/lua-http/contents/{+path}","compare_url":"https://api.github.com/repos/daurnimator/lua-http/compare/{base}...{head}","merges_url":"https://api.github.com/repos/daurnimator/lua-http/merges","archive_url":"https://api.github.com/repos/daurnimator/lua-http/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/daurnimator/lua-http/downloads","issues_url":"https://api.github.com/repos/daurnimator/lua-http/issues{/number}","pulls_url":"https://api.github.com/repos/daurnimator/lua-http/pulls{/number}","milestones_url":"https://api.github.com/repos/daurnimator/lua-http/milestones{/number}","notifications_url":"https://api.github.com/repos/daurnimator/lua-http/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/daurnimator/lua-http/labels{/name}","releases_url":"https://api.github.com/repos/daurnimator/lua-http/releases{/id}","deployments_url":"https://api.github.com/repos/daurnimator/lua-http/deployments","created_at":"2015-01-29T02:09:13Z","updated_at":"2016-12-09T22:52:18Z","pushed_at":"2016-12-08T14:33:13Z","git_url":"git://github.com/daurnimator/lua-http.git","ssh_url":"git@github.com:daurnimator/lua-http.git","clone_url":"https://github.com/daurnimator/lua-http.git","svn_url":"https://github.com/daurnimator/lua-http","homepage":"","size":1282,"stargazers_count":112,"watchers_count":112,"language":"Lua","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":14,"mirror_url":null,"open_issues_count":17,"forks":14,"open_issues":17,"watchers":112,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/daurnimator/lua-http/pulls/58"},"html":{"href":"https://github.com/daurnimator/lua-http/pull/58"},"issue":{"href":"https://api.github.com/repos/daurnimator/lua-http/issues/58"},"comments":{"href":"https://api.github.com/repos/daurnimator/lua-http/issues/58/comments"},"review_comments":{"href":"https://api.github.com/repos/daurnimator/lua-http/pulls/58/comments"},"review_comment":{"href":"https://api.github.com/repos/daurnimator/lua-http/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/daurnimator/lua-http/pulls/58/commits"},"statuses":{"href":"https://api.github.com/repos/daurnimator/lua-http/statuses/0e2df19d810a7bf92d33ea27d071d1872e8eb431"}}}}
{"actor":{"display_login":"daurnimator"}}