尝试使用_FIND时CouchDB中需要的Referer标头错误(";REFERER HEADER) [英] "Referer Header Required" error in couchdb when trying to use _find
问题描述
我正在开始使用CouchDB,并且已经开始构建应用程序。我可以使用curl写和读得很好,但是我已经开始尝试使用_find进行搜索,我得到了一个错误,声明"Referer Header Required"(需要Referer Header)。
curl -X POST http://localhost:5984/mydb/_find -d '{"selector":{"member.email":"foo@bar.com"}}
退货:
{"error":"bad_request","reason":"Referer header required."}
当我尝试在调用中添加"Referer"主机时,它只说Referer需要匹配主机,但我不知道它是什么意思。
curl -X POST http://localhost:5984/mydb/_find -d '{"selector":{"member.email":"matthew"}}' -H "Referer: localhost"
{"error":"bad_request","reason":"Referer header must match host."}
我尝试了各种组合,使用localhost,使用带和不带端口号的组合,尝试使用X-Forwarded-Host,我找到了十几篇关于POST和PUT以及版本控制的相关文章,但是我走到了死胡同,就是找不到我错过了什么。
nb.我在OSX笔记本电脑上运行Couchdb1.7.x。
推荐答案
我通过查看源代码设法修复了Referer header required
和随后的Referer header must match host
。虽然真正的问题是期望_find在旧的1.X版本中工作,但OS包管理器默认使用这些版本。最好升级到最新版本的CouchDB(3.1.1)。
您可以通过将vhosts添加到配置文件/etc/couchdb/local.ini
[vhosts]
;localhost = /db/
localhost = /*
[httpd]
x_forwarded_host = Y-Forwarded-Host
并且可能还使用X-Forwarded-Host的自定义标头名称,在我的例子中,获取API调用的软件对X-Forwarded-Host和Host标头做了一些非常聪明的事情。
因此,当您调用CouchDB时,只需将新标头与"localhost"一起包含
curl -X POST http://localhost:5984/mydb/_find
-H 'Referer: localhost'
-H 'Y-Forwarded-Host: localhost'
-d '{"selector":{"member.email":"foo@bar.com"}}
或为空,以便它们匹配
curl -X POST http://localhost:5984/mydb/_find
-H 'Referer'
-H 'X-Forwarded-Host'
-d '{"selector":{"member.email":"foo@bar.com"}}
在版本2或3之后的版本中,这两个标头都不需要,它们已恢复正常。
这篇关于尝试使用_FIND时CouchDB中需要的Referer标头错误(";REFERER HEADER)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!