Skip to content

Commit

Permalink
Merge pull request #1273 from scplsy/issue_1272
Browse files Browse the repository at this point in the history
fix: 单体服务pypi simple重定向到错误的url #1272
  • Loading branch information
owenlxu authored Oct 24, 2023
2 parents 89f8db6 + 69070ed commit 52d94be
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ import java.time.format.DateTimeFormatter
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
import javax.servlet.http.HttpServletRequest

@Component
class PypiLocalRepository(
Expand Down Expand Up @@ -336,21 +335,19 @@ class PypiLocalRepository(
/**
* 本地调试删除 pypi.domain 配置
*/
fun getRedirectUrl(request: HttpServletRequest): String {
fun getRedirectUrl(path: String): String {
val domain = pypiProperties.domain
val path = request.servletPath
return UrlFormatter.format(domain, path).ensureSuffix(StringPool.SLASH)
}

/**
*
*/
fun getSimpleHtml(artifactInfo: ArtifactInfo): Any? {
val request = HttpContextHolder.getRequest()
if (!request.requestURI.endsWith("/")) {
val path = ArtifactContextHolder.getUrlPath(this.javaClass.name)!!
if (!path.endsWith("/")) {
val response = HttpContextHolder.getResponse()
response.sendRedirect(getRedirectUrl(request))
response.writer.flush()
response.sendRedirect(getRedirectUrl(path))
return null
}
with(artifactInfo) {
Expand Down

0 comments on commit 52d94be

Please sign in to comment.