Skip to main content

Send HEAD request (http.head)

Declaration

code, res_headers_json = http.head(URL [, timeout_secs, headers, url_no_escape])

Declaration (named arguments)

Supported since 20250625

code, res_headers_json, body = http.head{
url = URL;
timeout = timeout_secs;
headers = headers;
params = query_params;
}

Parameters

  • URL
    String. Request URL. The function escapes the URL by default; see "url_no_escape" if you don't want this.
  • timeout_secs
    Number, optional. Timeout in seconds. Default 10.
  • headers
    Table, optional. Request headers in the form { field1 = value1, ... }. Default {}.
  • query_params
    Table, optional. Query string parameters in the form { field1 = value1, ... }. Default {}.
  • url_no_escape
    Boolean, optional. true = do not escape URL. Default false.
    For custom escaping, see the lcurl module easy:escape and easy:unescape.

Returns

  • code
    Integer. HTTP status code. -1 on timeout.
  • res_headers_json
    String or nil. Response headers in JSON. nil on timeout.

Notes

Use HTTP/1.1 HEAD method to fetch response headers.
HEAD typically returns the same headers as GET but without body.
This function may yield; other threads may run before it returns.

Example

local c, h = http.head("https://www.xxtouch.app/测试文本.txt")
if c==200 then
sys.alert(h)
end

Note: Uses sys.alert