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

Custom Static File Handling implementation #2174

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zugazagoitia
Copy link
Member

@zugazagoitia zugazagoitia commented Mar 3, 2024

Draft PR of the in-progress work to implement a non-Jetty dependent Static Files Handler, aiming to maintain maximum compatibility with the current API and Behaviour.

Related to #2164

import kotlin.io.path.Path
import kotlin.io.path.absolute

class ResourceHandlerImpl(val pvt: PrivateConfig) : ResourceHandler {
Copy link
Member

Choose a reason for hiding this comment

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

ResourceHandlerImpl -> DefaultResourceHandler or JavalinResourceHandler

@@ -351,6 +353,7 @@ class TestStaticFiles {
}

@Test
@Suppress("Javalin 7 will have an immutable instance")
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to push this out during 6x.

Comment on lines +32 to +41
override fun canHandle(ctx: Context): Boolean = nonSkippedHandlers(ctx.req()).any { handler ->
return try {
fileOrWelcomeFile(handler, ctx.path()) != null
} catch (e: Exception) {
e.message?.contains("Rejected alias reference") == true || // we want to say these are un-handleable (404)
e.message?.contains("Failed alias check") == true || // we want to say these are un-handleable (404)
e.message?.contains("Path is outside of the base directory") == true // we want to say these are un-handleable (404)

}
}
Copy link
Member

Choose a reason for hiding this comment

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

It should be possible to simplify this a lot in the new setup

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.

None yet

2 participants