EDU-4212 Enable About service for academy.jetbrains.com

GitOrigin-RevId: 0d39bed93d8ba4ae69d8038ef1091722feb297ba
This commit is contained in:
Aleksey Rostovskiy
2021-05-19 05:26:46 +03:00
committed by intellij-monorepo-bot
parent b806fbc515
commit b567009acd

View File

@@ -52,14 +52,24 @@ internal class AboutHttpService : RestService() {
override fun isOriginAllowed(request: HttpRequest): OriginCheckResult {
val originAllowed = super.isOriginAllowed(request)
if (originAllowed == OriginCheckResult.FORBID) {
val origin = request.origin ?: return OriginCheckResult.FORBID
@Suppress("SpellCheckingInspection")
return if (origin.matches(Regex("https://([a-z0-9-]+\\.)*hyperskill.org$"))) OriginCheckResult.ALLOW else OriginCheckResult.FORBID
if (originAllowed == OriginCheckResult.FORBID && request.isEduToolsPluginRelated()) {
return OriginCheckResult.ALLOW
}
return originAllowed
}
/**
* [EduTools](https://plugins.jetbrains.com/plugin/10081-edutools) plugin requires IDE to respond with its version
* from hyperskill.org and academy.jetbrains.com sites
*/
private fun HttpRequest.isEduToolsPluginRelated(): Boolean {
val origin = origin ?: return false
@Suppress("SpellCheckingInspection")
val hyperskillRegex = Regex("https://([a-z0-9-]+\\.)*hyperskill.org$")
val academyJetbrainsRegex = Regex("https://([a-z0-9-]+)*.jetbrains.com$")
return origin.matches(hyperskillRegex) || origin.matches(academyJetbrainsRegex)
}
override fun execute(urlDecoder: QueryStringDecoder, request: FullHttpRequest, context: ChannelHandlerContext): String? {
val byteOut = BufferExposingByteArrayOutputStream()
writeApplicationInfoJson(byteOut, urlDecoder, request.isLocalOrigin())