[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add curl test for redirect plugin's http_to_https. #6378

Merged

Conversation

mangoGoForward
Copy link
Contributor

What this PR does / why we need it:

Add curl test for redirect plugin's http_to_https, please see #3931.

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

$ curl http://127.0.0.1:9080/hello -i
HTTP/1.1 301 Moved Permanently
...
Location: https://127.0.0.1/hello
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we use 9080 to accept HTTP traffic, should we use 9443 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should be 9443? and the default port of https is 443.
When http_to_https is set to true and the request is HTTP, it will be automatically redirected to HTTPS with 301 response code, and the URI will keep the same as client request.

if conf.http_to_https and _scheme == "http" then
-- TODO: add test case
-- PR: https://github.com/apache/apisix/pull/1958
uri = "https://$host$request_uri"
local method_name = ngx.req.get_method()
if method_name == "GET" or method_name == "HEAD" then
ret_code = 301
else
-- https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308
ret_code = 308
end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should be 9443

The default port for the APISIX proxy https protocol is 9443.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mangoGoForward Just for the consistence of the documentation, look through the whole doc you'll find we don't use the default 80 port.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default port for the APISIX proxy https protocol is 9443.

@tokers See the Location header of response, it redirected to https. And I found some test cases in t/plugin/redirect.t:

apisix/t/plugin/redirect.t

Lines 431 to 438 in 42e84e4

=== TEST 18: redirect
--- request
GET /hello
--- more_headers
Host: foo.com
--- error_code: 301
--- response_headers
Location: https://foo.com/hello

Seems we don't need to update?

Copy link
Contributor
@tokers tokers Feb 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I think there is a bug, The generated Location header should respect the setting of SSL port, we cannot assume the SSL port is 443.

Also, my original meaning is quite simple, just because we use 9080 as the sample port to accept HTTP traffic in the doc, for the sake for consistence, I think using 9443 is better. If we use 80 to accept HTTP traffic, then using 443 is better.

Copy link
Contributor Author
@mangoGoForward mangoGoForward Feb 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't know how to use 9443 in this test case.
Do we need create an upstream?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR does not need to be modified in the test case to 9443, just use 9443 in the documentation? cc @tokers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping @tokers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tzssangglass is correct, just use 9443 in documentation is enough.

docs/en/latest/plugins/redirect.md Outdated Show resolved Hide resolved
docs/zh/latest/plugins/redirect.md Outdated Show resolved Hide resolved
mangoGoForward and others added 2 commits March 8, 2022 09:40
Co-authored-by: tzssangglass <tzssangglass@gmail.com>
Co-authored-by: tzssangglass <tzssangglass@gmail.com>
@spacewander spacewander merged commit 1853bc8 into apache:master Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants