From f97dc8489d58aef2d038288f9a8bc69f907e17bb Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 22 Mar 2022 19:21:58 +0100 Subject: fix(docs) fix html linter issues in the docs (#358) --- doc/http.html | 142 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 72 insertions(+), 70 deletions(-) (limited to 'doc/http.html') diff --git a/doc/http.html b/doc/http.html index 78f785a..52b8a30 100644 --- a/doc/http.html +++ b/doc/http.html @@ -1,10 +1,10 @@ - - + LuaSocket: HTTP support @@ -13,22 +13,22 @@ -
+

- -
-LuaSocket +
+LuaSocket
Network support for the Lua language +
Network support for the Lua language
-

+

home · download · introduction · introduction · -reference +reference


@@ -36,12 +36,12 @@ -

HTTP

+

HTTP

HTTP (Hyper Text Transfer Protocol) is the protocol used to exchange information between web-browsers and servers. The http -namespace offers full support for the client side of the HTTP +namespace offers full support for the client side of the HTTP protocol (i.e., the facilities that would be used by a web-browser implementation). The implementation conforms to the HTTP/1.1 standard, @@ -50,16 +50,16 @@ implementation conforms to the HTTP/1.1 standard,

The module exports functions that provide HTTP functionality in different -levels of abstraction. From the simple +levels of abstraction. From the simple string oriented requests, through generic LTN12 based, down to even lower-level if you bother to look through the source code.

-

+

To obtain the http namespace, run:

-
+
 -- loads the HTTP module and any libraries it requires
 local http = require("socket.http")
 
@@ -67,12 +67,12 @@ local http = require("socket.http")

URLs must conform to RFC 1738, -that is, an URL is a string in the form: +that is, an URL is a string in the form:

-[http://][<user>[:<password>]@]<host>[:<port>][/<path>] 
+[http://][<user>[:<password>]@]<host>[:<port>][/<path>]
 
@@ -97,34 +97,34 @@ headers = {

Field names are case insensitive (as specified by the standard) and all functions work with lowercase field names (but see -socket.headers.canonic). +socket.headers.canonic). Field values are left unmodified.

-

+

Note: MIME headers are independent of order. Therefore, there is no problem -in representing them in a Lua table. +in representing them in a Lua table.

The following constants can be set to control the default behavior of -the HTTP module: +the HTTP module:

    -
  • PROXY: default proxy used for connections; -
  • TIMEOUT: sets the timeout for all I/O operations; -
  • USERAGENT: default user agent reported to server. +
  • PROXY: default proxy used for connections;
  • +
  • TIMEOUT: sets the timeout for all I/O operations;
  • +
  • USERAGENT: default user agent reported to server.
-

+

Note: These constants are global. Changing them will also change the behavior other code that might be using LuaSocket.

-

+

http.request(url [, body])
http.request{
  url = string,
@@ -140,26 +140,26 @@ http.request{
}

-

-The request function has two forms. The simple form downloads -a URL using the GET or POST method and is based -on strings. The generic form performs any HTTP method and is -LTN12 based. +

+The request function has two forms. The simple form downloads +a URL using the GET or POST method and is based +on strings. The generic form performs any HTTP method and is +LTN12 based.

-

+

If the first argument of the request function is a string, it should be an url. In that case, if a body is provided as a string, the function will perform a POST method in the url. Otherwise, it performs a GET in the -url +url

-

-If the first argument is instead a table, the most important fields are +

+If the first argument is instead a table, the most important fields are the url and the simple -LTN12 -sink that will receive the downloaded content. +LTN12 +sink that will receive the downloaded content. Any part of the url can be overridden by including the appropriate field in the request table. If authentication information is provided, the function @@ -169,49 +169,51 @@ function discards the downloaded data. The optional parameters are the following:

    -
  • method: The HTTP request method. Defaults to "GET"; -
  • headers: Any additional HTTP headers to send with the request; -
  • source: simple -LTN12 +
  • method: The HTTP request method. Defaults to "GET";
  • +
  • headers: Any additional HTTP headers to send with the request;
  • +
  • source: simple +LTN12 source to provide the request body. If there is a body, you need to provide an appropriate "content-length" request header field, or the function will attempt to send the body as -"chunked" (something few servers support). Defaults to the empty source; -
  • step: -LTN12 -pump step function used to move data. -Defaults to the LTN12 pump.step function. -
  • proxy: The URL of a proxy server to use. Defaults to no proxy; -
  • redirect: Set to false to prevent the -function from automatically following 301 or 302 server redirect messages; +"chunked" (something few servers support). Defaults to the empty source;
  • +
  • step: +LTN12 +pump step function used to move data. +Defaults to the LTN12 pump.step function.
  • +
  • proxy: The URL of a proxy server to use. Defaults to no proxy;
  • +
  • redirect: Set to false to prevent the +function from automatically following 301 or 302 server redirect messages;
  • create: An optional function to be used instead of -socket.tcp when the communications socket is created. -
  • maxredirects: An optional number specifying the maximum number of redirects to follow. Defaults to 5 if not specified. A boolean false value means no maximum (unlimited). +socket.tcp when the communications socket is created.
  • +
  • maxredirects: An optional number specifying the maximum number of + redirects to follow. Defaults to 5 if not specified. A boolean + false value means no maximum (unlimited).
-

+

In case of failure, the function returns nil followed by an -error message. If successful, the simple form returns the response +error message. If successful, the simple form returns the response body as a string, followed by the response status code, the response headers and the response status line. The generic function returns the same information, except the first return value is just the number 1 (the body goes to the sink).

-

-Even when the server fails to provide the contents of the requested URL (URL not found, for example), +

+Even when the server fails to provide the contents of the requested URL (URL not found, for example), it usually returns a message body (a web page informing the URL was not found or some other useless page). To make sure the operation was successful, check the returned status code. For a list of the possible values and their meanings, refer to RFC 2616. +href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616.

-

+

Here are a few examples with the simple interface:

-
+
 -- load the http module
 local io = require("io")
 local http = require("socket.http")
@@ -219,15 +221,15 @@ local ltn12 = require("ltn12")
 
 -- connect to server "www.cs.princeton.edu" and retrieves this manual
 -- file from "~diego/professional/luasocket/http.html" and print it to stdout
-http.request{ 
-    url = "http://www.cs.princeton.edu/~diego/professional/luasocket/http.html", 
+http.request{
+    url = "http://www.cs.princeton.edu/~diego/professional/luasocket/http.html",
     sink = ltn12.sink.file(io.stdout)
 }
 
 -- connect to server "www.example.com" and tries to retrieve
 -- "/private/index.html". Fails because authentication is needed.
 b, c, h = http.request("http://www.example.com/private/index.html")
--- b returns some useless page telling about the denied access, 
+-- b returns some useless page telling about the denied access,
 -- h returns authentication information
 -- and c returns with value 401 (Authentication Required)
 
@@ -237,11 +239,11 @@ r, e = http.request("http://wrong.host/")
 -- r is nil, and e returns with value "host not found"
 
-

+

And here is an example using the generic interface:

-
+
 -- load the http module
 http = require("socket.http")
 
@@ -263,7 +265,7 @@ r, c, h = http.request {
 -- }
 
-

+

Note: When sending a POST request, simple interface adds a "Content-type: application/x-www-form-urlencoded" header to the request. This is the type used by @@ -271,21 +273,21 @@ HTML forms. If you need another type, use the generic interface.

-

+

Note: Some URLs are protected by their servers from anonymous download. For those URLs, the server must receive some sort of authentication along with the request or it will deny -download and return status "401 Authentication Required". +download and return status "401 Authentication Required".

-

+

The HTTP/1.1 standard defines two authentication methods: the Basic Authentication Scheme and the Digest Authentication Scheme, both explained in detail in RFC 2068.

-

The Basic Authentication Scheme sends +

The Basic Authentication Scheme sends <user> and <password> unencrypted to the server and is therefore considered unsafe. Unfortunately, by the time of this implementation, @@ -294,7 +296,7 @@ Therefore, this is the method used by the toolkit whenever authentication is required.

-
+
 -- load required modules
 http = require("socket.http")
 mime = require("mime")
@@ -314,15 +316,15 @@ r, c = http.request {
 
 
 
-