Skip to content

Commit 3bae4ee

Browse files
committed
Better user-agent format and made user-agent available at the module level
1 parent 001e312 commit 3bae4ee

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/resty/http.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ end
6868
local _M = {
6969
_VERSION = '0.05',
7070
}
71+
_M._USER_AGENT = "lua-resty-http/" .. _M._VERSION .. " (Lua) ngx_lua/" .. ngx.config.ngx_lua_version
7172

7273
local mt = { __index = _M }
7374

@@ -77,8 +78,6 @@ local HTTP = {
7778
[1.1] = " HTTP/1.1\r\n",
7879
}
7980

80-
local USER_AGENT = "Resty/HTTP " .. _M._VERSION .. " (Lua)"
81-
8281
local DEFAULT_PARAMS = {
8382
method = "GET",
8483
path = "/",
@@ -517,7 +516,7 @@ function _M.send_request(self, params)
517516
headers["Host"] = self.host
518517
end
519518
if not headers["User-Agent"] then
520-
headers["User-Agent"] = USER_AGENT
519+
headers["User-Agent"] = _M._USER_AGENT
521520
end
522521
if params.version == 1.0 and not headers["Connection"] then
523522
headers["Connection"] = "Keep-Alive"

0 commit comments

Comments
 (0)