Home

Awesome

Name

lua-resty-http -simple- Simple Lua HTTP client driver for ngx_lua

Example

server {
  location /test {
    content_by_lua '
      local http   = require "resty.http.simple"

      local res, err = http.request("checkip.amazonaws.com", 80, {
      headers = { Cookie = "foo=bar"} })
      if not res then
        ngx.say("http failure: ", err)
        return
      end

      if res.status >= 200 and res.status < 300 then
        ngx.say("My IP is: " .. res.body)
      else
        ngx.say("Query returned a non-200 response: " .. res.status)
      end
    ';
  }
}

API

request

syntax: local res, err = http.request(host, port, options?)

Perform an http request.

Before actually resolving the host name and connecting to the remote backend, this method will always look up the connection pool for matched idle connections created by previous calls of this method. This allows the module to handle HTTP keep alives.

An optional Lua options table can be specified to declare various options:

Returns a res object containing three attributes:

Note All headers (request and response) are noramlized for capitalization - e.g., Accept-Encoding, ETag, Foo-Bar, Baz - in the normal HTTP "standard."

Licence

Started life as a fork of lua-resty-http - Copyright (c) 2013 Black Square Media Ltd

This code is covered by MIT License.

Copyright (C) 2013, by Brian Akins brian@akins.org.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.