httpc request twice,the second time return err of closed
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 30/100
Research direction
Start with the posted Lua script and compare the two httpc:request_uri calls, including the URL value passed to the second call. Verify the intended response-derived URL and confirm that the second request completes without the closed error.
Written by the indexing model from the issue text.
Description
`
-- 引入必要的Lua库
local http = require("resty.http")
-- 创建全局的连接池
local httpc_pool = {}
-- 获取参数变量url
local url = ngx.var.arg_url
if not url then
ngx.status = ngx.HTTP_BAD_REQUEST
ngx.say("Missing 'url' parameter")
ngx.exit(ngx.HTTP_BAD_REQUEST)
end
-- 从连接池中获取连接
local httpc = httpc_pool[url]
if not httpc then
-- 连接池中没有可用的连接,创建一个新的连接
httpc = http.new()
httpc_pool[url] = httpc
end
-- 发起HTTP请求获取URL的响应
local res, err = httpc:request_uri(url, {
method = "GET",
ssl_verify = false,
headers = {
["User-Agent"] = "Mozilla/5.0 (compatible; Lua-resty-http/0.15; +https://github.com/pintsized/lua-resty-http)",
}
})
if not res then
ngx.status = ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.say("Failed to request meiya image URL: ", err)
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
end
-- 获取响应的文本内容
local body = res.body
-- 请求并返回图片数据
res, err = httpc:request_uri("body ", {
method = "GET",
ssl_verify = false,
headers = {
["User-Agent"] = "Mozilla/5.0 (compatible; Lua-resty-http/0.15; +https://github.com/pintsized/lua-resty-http)",
}
})
if not res then
ngx.log(ngx.ERR, "request err.", err)
ngx.status = ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.say('请求失败!',err)
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
end
ngx.header["Content-Type"] = res.headers["Content-Type"]
ngx.print(res.body)
ngx.flush(true)
`
this is my lua script; when i modify body as url constant, the second reuqest is all right. when body is a variable, second request's res is nil and err msg is closed.
can anyone figure out code's mistake?
- Dominant language
- Lua
- Stars
- 2.1k
- Forks
- 630
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ledgetech/lua-resty-http
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
ledgetech/lua-resty-http#337 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ledgetech/lua-resty-http#334 · 1 comment · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ledgetech/lua-resty-http#330 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 15/100
ledgetech/lua-resty-http#325 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ledgetech/lua-resty-http#324 ·
All issues in ledgetech/lua-resty-http
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
api7/lua-resty-saml#62 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
nvim-tree/nvim-tree.lua#3357 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
codymikol/multiverse.nvim#320 ·
-
Data Correction tbc
Difficulty 2/5 1-3 hours Newbie friendliness 68/100