【发布时间】:2019-12-13 21:39:43
【问题描述】:
我在 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
当我 curl get 策略时,我收到 200 响应:
$ curl -X POST localhost:8181/v0/data/main/get
[{"body":{},"raw_body":"{}","status":"200 OK","status_code":200}]
但是,当我 curl 放置策略时,它会在 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 -X PUT -d "{}" http://localhost:8181/v1/data/example
我知道这是一个奇怪/糟糕的“用例”,但出于好奇,我想更好地了解 rego http 功能中发生了什么。
【问题讨论】: