我在一个main
包中有两个策略,它们调用同一个实例(本地运行的 OPA 服务器),如下所示:
package main
get[response] {
response := http.send({
"method" : "GET",
"url": "http://localhost:8181/v1/data/example"
})
}
put[response] {
response := http.send({
"method" : "PUT",
"url": "http://localhost:8181/v1/data/example",
"body": { "example": true }
})
}
我像这样运行我的 OPA 服务器:
opa run -w -s main.rego --log-level debug --log-format text
当我 curlget
策略时,我得到 200 响应:
$ curl -X POST localhost:8181/v0/data/main/get
[{"body":{},"raw_body":"{}","status":"200 OK","status_code":200}]
但是,当我卷曲 put 策略时,它会在 5 秒后超时:
$ curl -X POST localhost:8181/v0/data/main/put
{
"code": "internal_error",
"message": "error(s) occurred while evaluating query",
"errors": [
{
"code": "eval_builtin_error",
"message": "http.send: Put http://localhost:8181/v1/data/example: net/http: request canceled (Client.Timeout exceeded while awaiting headers)",
"location": {
"file": "main.rego",
"row": 11,
"col": 14
}
}
]
}
有谁知道为什么会发生这种情况PUT
而不是GET
针对 OPA 实例的请求?
同时,类似的 curl 效果很好:
curl -X PUT -d "{}" http://localhost:8181/v1/data/example
我知道这是一个奇怪/糟糕的“用例”,但出于好奇,我想更好地了解 rego http 功能中发生了什么。