-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19750][UI][branch-2.1] Fix redirect issue from http to https #17083
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -330,7 +330,7 @@ private[spark] object JettyUtils extends Logging { | |
|
|
||
| // redirect the HTTP requests to HTTPS port | ||
| httpConnector.setName(REDIRECT_CONNECTOR_NAME) | ||
| collection.addHandler(createRedirectHttpsHandler(securePort, scheme)) | ||
| collection.addHandler(createRedirectHttpsHandler(connector, scheme)) | ||
| Some(connector) | ||
|
|
||
| case None => | ||
|
|
@@ -378,7 +378,8 @@ private[spark] object JettyUtils extends Logging { | |
| server.getHandler().asInstanceOf[ContextHandlerCollection]) | ||
| } | ||
|
|
||
| private def createRedirectHttpsHandler(securePort: Int, scheme: String): ContextHandler = { | ||
| private def createRedirectHttpsHandler( | ||
| httpsConnector: ServerConnector, scheme: String): ContextHandler = { | ||
|
||
| val redirectHandler: ContextHandler = new ContextHandler | ||
| redirectHandler.setContextPath("/") | ||
| redirectHandler.setVirtualHosts(Array("@" + REDIRECT_CONNECTOR_NAME)) | ||
|
|
@@ -391,8 +392,8 @@ private[spark] object JettyUtils extends Logging { | |
| if (baseRequest.isSecure) { | ||
| return | ||
| } | ||
| val httpsURI = createRedirectURI(scheme, baseRequest.getServerName, securePort, | ||
| baseRequest.getRequestURI, baseRequest.getQueryString) | ||
| val httpsURI = createRedirectURI(scheme, baseRequest.getServerName, | ||
| httpsConnector.getLocalPort, baseRequest.getRequestURI, baseRequest.getQueryString) | ||
| response.setContentLength(0) | ||
| response.encodeRedirectURL(httpsURI) | ||
| response.sendRedirect(httpsURI) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -267,8 +267,11 @@ class UISuite extends SparkFunSuite { | |
| s"$scheme://localhost:$port/test1/root", | ||
| s"$scheme://localhost:$port/test2/root") | ||
| urls.foreach { url => | ||
| val rc = TestUtils.httpResponseCode(new URL(url)) | ||
| assert(rc === expected, s"Unexpected status $rc for $url") | ||
| val rc = TestUtils.httpResponseCodeAndURL(new URL(url)) | ||
|
||
| assert(rc._1 === expected, s"Unexpected status $rc for $url") | ||
| if (rc._1 == HttpServletResponse.SC_FOUND) { | ||
| assert(TestUtils.httpResponseCode(new URL(rc._2.get)) === HttpServletResponse.SC_OK) | ||
| } | ||
| } | ||
| } | ||
| } finally { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So is there a reason why you didn't make this a single line change to pass the correct port?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vanzin , AFAIK in this code, at that time when we create a redirect handler, the https
ServerConnectorhasn't yet started, so we couldn't get the real port from it, it will return -1 as we callgetLocalPort.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point. I guess I was thinking about the code in master which starts the connector right away.