You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/02/01 12:57:07 UTC
[GitHub] [incubator-apisix] renyineng opened a new issue #1100: bug: 浏览器发送 OPTIONS请求,无法匹配header, CURL请求没问题
renyineng opened a new issue #1100: bug: 浏览器发送 OPTIONS请求,无法匹配header, CURL请求没问题
URL: https://github.com/apache/incubator-apisix/issues/1100
### Issue description
浏览器发送 OPTIONS请求,无法匹配到header(无法读取到),导致了404, 发送 CURL请求没问题
### Environment
* apisix version v1.0
* OS: centos7
### Minimal test code / Steps to reproduce the issue
1.新增路由
```
curl http://127.0.0.1:80/apisix/admin/routes/1 -X PUT -d '
{
"uri": "/shop/auth/login",
"methods": ["OPTIONS","POST"],
"vars": [
["http_k_project", "shop"]
],
"service_id": "1"
}
```
2. 使用 vue axios 发送post请求,因为涉及跨域,所以先发送了OPTIONS请求,则直接404了
3. 使用curl测试 正常
`curl -I -X OPTIONS https://api.xxx.com/shop/auth/login -H "Host:api.xxx.com" -H "Content-Type:application/json" -H "Accept:application/json" -H "K-Project:shop"`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-apisix] chenqing24 commented on issue #1100: bug: 【CORS Problem】Browser auto sends OPTIONS request, cannot match header, CURL request is fine
Posted by GitBox <gi...@apache.org>.
chenqing24 commented on issue #1100: bug: 【CORS Problem】Browser auto sends OPTIONS request, cannot match header, CURL request is fine
URL: https://github.com/apache/incubator-apisix/issues/1100#issuecomment-602517208
Here is my solution for your reference:
```lua
function _M.rewrite(conf, ctx)
-- 在开头先判断,如果是游览器为了跨域而发的OPTIONS,直接返回OK
if 'OPTIONS' == action then
return 200
end
……
end
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-apisix] membphis closed issue #1100: bug: 【CORS Problem】Browser auto sends OPTIONS request, cannot match header, CURL request is fine
Posted by GitBox <gi...@apache.org>.
membphis closed issue #1100: bug: 【CORS Problem】Browser auto sends OPTIONS request, cannot match header, CURL request is fine
URL: https://github.com/apache/incubator-apisix/issues/1100
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-apisix] membphis commented on issue #1100: bug: 【CORS Problem】Browser auto sends OPTIONS request, cannot match header, CURL request is fine
Posted by GitBox <gi...@apache.org>.
membphis commented on issue #1100: bug: 【CORS Problem】Browser auto sends OPTIONS request, cannot match header, CURL request is fine
URL: https://github.com/apache/incubator-apisix/issues/1100#issuecomment-603268207
https://github.com/apache/incubator-apisix/pull/1327/files#diff-5caafc33851762ad95581b482d00332aR137
New PR has been submitted, we can close this issue now
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-apisix] renyineng commented on issue #1100: bug: Browser
sends OPTIONS request, cannot match header, CURL request is fine
Posted by GitBox <gi...@apache.org>.
renyineng commented on issue #1100: bug: Browser sends OPTIONS request, cannot match header, CURL request is fine
URL: https://github.com/apache/incubator-apisix/issues/1100#issuecomment-581030505
The options request automatically sent by the browser does not carry parameters, so it does not match.
https://medium.com/@hjyker/%E9%A2%84%E6%A3%80%E8%AF%B7%E6%B1%82-options-dff67adfeb66
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-apisix] renyineng commented on issue #1100: bug: Browser
sends OPTIONS request, cannot match header, CURL request is fine
Posted by GitBox <gi...@apache.org>.
renyineng commented on issue #1100: bug: Browser sends OPTIONS request, cannot match header, CURL request is fine
URL: https://github.com/apache/incubator-apisix/issues/1100#issuecomment-581029682
The OPTIONS that the browser sends automatically across domains does not pass the header, so it does n’t work in the browser, CURL is OK
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-apisix] chenqing24 edited a comment on issue #1100: bug: 【CORS Problem】Browser auto sends OPTIONS request, cannot match header, CURL request is fine
Posted by GitBox <gi...@apache.org>.
chenqing24 edited a comment on issue #1100: bug: 【CORS Problem】Browser auto sends OPTIONS request, cannot match header, CURL request is fine
URL: https://github.com/apache/incubator-apisix/issues/1100#issuecomment-602517208
Here is my solution for your reference:
```lua
function _M.rewrite(conf, ctx)
-- 在开头先判断,如果是游览器为了跨域而发的OPTIONS,直接返回OK
if 'OPTIONS' == ctx.var.request_method then
return 200
end
……
end
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-apisix] membphis commented on issue #1100: bug: 浏览器发送 OPTIONS请求,无法匹配header, CURL请求没问题
Posted by GitBox <gi...@apache.org>.
membphis commented on issue #1100: bug: 浏览器发送 OPTIONS请求,无法匹配header, CURL请求没问题
URL: https://github.com/apache/incubator-apisix/issues/1100#issuecomment-581028414
I made a test right now, it works fine. please take a look:
```shell
$ curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
"uri": "/shop/auth/login",
"methods": ["OPTIONS","POST"],
"vars": [
["http_k_project", "shop"]
],
"plugins": {
"redirect": {
"uri": "/test/default.html",
"ret_code": 301
}
}
}'
HTTP/1.1 200 OK
Date: Sat, 01 Feb 2020 13:02:42 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
... ...
# expect: hit
$ curl -I -X OPTIONS http://127.0.0.1:9080/shop/auth/login -H "K-Project: shop"
HTTP/1.1 301 Moved Permanently
Date: Sat, 01 Feb 2020 13:03:33 GMT
Content-Type: text/html
Content-Length: 166
Connection: keep-alive
Location: /test/default.html
Server: APISIX web server
... ...
# expect: not hit
$ curl -I -X OPTIONS http://127.0.0.1:9080/shop/auth/login -H "K-Project: shop1"
HTTP/1.1 404 Not Found
Date: Sat, 01 Feb 2020 13:03:51 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX web server
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services