Skip to content

Commit

Permalink
Cleanup documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
xgouchet committed Nov 5, 2023
1 parent 4236c9b commit 77f4c5b
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 278 deletions.
31 changes: 8 additions & 23 deletions javalin/src/main/java/io/javalin/config/BundledPluginsConfig.kt
Expand Up @@ -16,7 +16,6 @@ import java.util.function.Consumer
/**
* Configuration to enable bundled plugins or add custom ones.
*
* @param cfg the parent Javalin Configuration
* @see [JavalinConfig.bundledPlugins]
*/
class BundledPluginsConfig(private val cfg: JavalinConfig) {
Expand All @@ -35,8 +34,6 @@ class BundledPluginsConfig(private val cfg: JavalinConfig) {

/**
* Enables the Basic Authentication plugin.
* @param username the authorized username
* @param password the authorized password
* @see [BasicAuthPlugin]
*/
fun enableBasicAuth(username: String, password: String) =
Expand All @@ -48,39 +45,27 @@ class BundledPluginsConfig(private val cfg: JavalinConfig) {
/**
* Enables the Global Headers plugin.
*
* @param globalHeaderConfig the global headers plugin configuration
* @see [GlobalHeadersPlugin]
*/
fun enableGlobalHeaders(globalHeadersConfig: Consumer<GlobalHeadersConfig>) = cfg.registerPlugin(GlobalHeadersPlugin(globalHeadersConfig))

/**
* Enables the Cors Plugin.
*
* @param userConfig the CORS plugin configuration
* @see [GlobalHeadersPlugin]
*/
fun enableCors(userConfig: Consumer<CorsPluginConfig>) = cfg.registerPlugin(CorsPlugin(userConfig))

/**
* Enables the HttpAllowedMethodsPlugin, automatically handling the Options request on configured routes.
*/
fun enableHttpAllowedMethodsOnRoutes() = cfg.registerPlugin(HttpAllowedMethodsPlugin())
/** Enables the HttpAllowedMethodsPlugin, automatically handling the Options request on configured routes. */
fun enableHttpAllowedMethodsOnRoutes() = cfg.registerPlugin(HttpAllowedMethods)

/**
* Enables the development debugging logger plugin.
*/
fun enableDevLogging() = cfg.registerPlugin(DevLoggingPlugin())
/** Enables the development debugging logger plugin. */
fun enableDevLogging() = cfg.registerPlugin(DevLogging)

/**
* Enables the RedirectToLowercasePath plugin.
*/
fun enableRedirectToLowercasePaths() = cfg.registerPlugin(RedirectToLowercasePathPlugin())
/** Enables the RedirectToLowercasePath plugin. */
fun enableRedirectToLowercasePaths() = cfg.registerPlugin(RedirectToLowercasePath)

/**
* Enables the SSL Redirects plugin, which redirect any http request to https.
*
* Note it must be the first plugin enabled to properly handle all requests.
*/
fun enableSslRedirects() = cfg.registerPlugin(SslRedirectPlugin())
/** Enables the SSL Redirects plugin, which redirect any http request to https. Note it must be the first plugin enabled to properly handle all requests.*/
fun enableSslRedirects() = cfg.registerPlugin(SslRedirect)

}
42 changes: 8 additions & 34 deletions javalin/src/main/java/io/javalin/config/EventConfig.kt
Expand Up @@ -28,51 +28,25 @@ import java.util.function.Consumer
*/
class EventConfig(private val cfg: JavalinConfig) {

/**
* Adds a callback to react on the Server Starting event.
* @param lifecycleEventListener the callback
*/
/** Adds a callback to react on the Server Starting event. */
fun serverStarting(lifecycleEventListener: LifecycleEventListener) = eventManager.addLifecycleEvent(SERVER_STARTING, lifecycleEventListener)
/**
* Adds a callback to react on the Server Started event.
* @param lifecycleEventListener the callback
*/
/** Adds a callback to react on the Server Started event. */
fun serverStarted(lifecycleEventListener: LifecycleEventListener) = eventManager.addLifecycleEvent(SERVER_STARTED, lifecycleEventListener)
/**
* Adds a callback to react on the Server Start Failed event.
* @param lifecycleEventListener the callback
*/
/** Adds a callback to react on the Server Start Failed event. */
fun serverStartFailed(lifecycleEventListener: LifecycleEventListener) = eventManager.addLifecycleEvent(SERVER_START_FAILED, lifecycleEventListener)
/**
* Adds a callback to react on the Server Stop Failed event.
* @param lifecycleEventListener the callback
*/
/** Adds a callback to react on the Server Stop Failed event. */
fun serverStopFailed(lifecycleEventListener: LifecycleEventListener) = eventManager.addLifecycleEvent(SERVER_STOP_FAILED, lifecycleEventListener)
/**
* Adds a callback to react on the Server Stopping event.
* @param lifecycleEventListener the callback
*/
/** Adds a callback to react on the Server Stopping event. */
fun serverStopping(lifecycleEventListener: LifecycleEventListener) = eventManager.addLifecycleEvent(SERVER_STOPPING, lifecycleEventListener)
/**
* Adds a callback to react on the Server Stopped event.
* @param lifecycleEventListener the callback
*/
/** Adds a callback to react on the Server Stopped event. */
fun serverStopped(lifecycleEventListener: LifecycleEventListener) = eventManager.addLifecycleEvent(SERVER_STOPPED, lifecycleEventListener)

/**
* Adds a callback to react when a [Handler] is added.
*
* @param callback the callback
*/
/** Adds a callback to react when a [Handler] is added. */
fun handlerAdded(callback: Consumer<HandlerMetaInfo>) {
eventManager.handlerAddedHandlers.add(callback);
}

/**
* Adds a callback to react when a websocket Handler is added.
*
* @param callback the callback
*/
/** Adds a callback to react when a websocket Handler is added. */
fun wsHandlerAdded(callback: Consumer<WsHandlerMetaInfo>) {
eventManager.wsHandlerAddedHandlers.add(callback);
}
Expand Down
25 changes: 5 additions & 20 deletions javalin/src/main/java/io/javalin/config/HttpConfig.kt
Expand Up @@ -20,46 +20,31 @@ class HttpConfig(private val cfg: JavalinConfig) {
@JvmField var asyncTimeout = 0L
//@formatter:on

/**
* Sets a custom CompressionStrategy.
* @param compressionStrategy the strategy to use
*/
/** Sets a custom CompressionStrategy. */
fun customCompression(compressionStrategy: CompressionStrategy) {
cfg.pvt.compressionStrategy = compressionStrategy
}

/**
* Sets a CompressionStrategy using both gzip and brotli.
* @param gzipLevel the gzip compression level
* @param brotliLevel the brotli compression level
*/
/** Sets a CompressionStrategy using both gzip and brotli.*/
@JvmOverloads
fun brotliAndGzipCompression(gzipLevel: Int = 6, brotliLevel: Int = 4) {
cfg.pvt.compressionStrategy = CompressionStrategy(Brotli(brotliLevel), Gzip(gzipLevel))
}

/**
* Sets a CompressionStrategy using gzip
* @param level the gzip compression level
*/
/** Sets a CompressionStrategy using gzip */
@JvmOverloads
fun gzipOnlyCompression(level: Int = 6) {
cfg.pvt.compressionStrategy = CompressionStrategy(null, Gzip(level))
}


/**
* Sets a CompressionStrategy using brotli.
* @param level the brotli compression level
*/
/** Sets a CompressionStrategy using brotli. */
@JvmOverloads
fun brotliOnlyCompression(level: Int = 4) {
cfg.pvt.compressionStrategy = CompressionStrategy(Brotli(level), null)
}

/**
* Disable Compression
*/
/** Disable Compression */
fun disableCompression() {
cfg.pvt.compressionStrategy = CompressionStrategy(null, null)
}
Expand Down
5 changes: 1 addition & 4 deletions javalin/src/main/java/io/javalin/config/JavalinConfig.kt
Expand Up @@ -60,14 +60,11 @@ class JavalinConfig {
* You can disable this behavior by setting this to false.
*/
@JvmField var startupWatcherEnabled = true
/**
* This is "private", only use it if you know what you're doing
*/
/** This is "private", only use it if you know what you're doing */
@JvmField val pvt = PrivateConfig(this)

/**
* Adds an event listener to this Javalin Configuration.
* @param listener the listener
* @see [EventConfig]
*/
fun events(listener:Consumer<EventConfig>) { listener.accept(this.events) }
Expand Down
10 changes: 2 additions & 8 deletions javalin/src/main/java/io/javalin/config/RequestLoggerConfig.kt
Expand Up @@ -12,18 +12,12 @@ import java.util.function.Consumer
*/
class RequestLoggerConfig(private val cfg: JavalinConfig) {

/**
* Adds a request logger for HTTP requests.
* @param requestLogger the request logger
*/
/** Adds a request logger for HTTP requests. */
fun http(requestLogger: RequestLogger) {
cfg.pvt.requestLogger = requestLogger
}

/**
* Adds a request logger for websocket requests.
* @param ws the request logger
*/
/** Adds a request logger for websocket requests. */
fun ws(ws: Consumer<WsConfig>) {
val logger = WsConfig()
ws.accept(logger)
Expand Down
16 changes: 4 additions & 12 deletions javalin/src/main/java/io/javalin/config/RouterConfig.kt
Expand Up @@ -20,24 +20,16 @@ import java.util.function.Consumer
class RouterConfig(internal val cfg: JavalinConfig) {

// @formatter:off
/**
* The context path (ex '/blog' if you are hosting an app on a subpath, like 'mydomain.com/blog')
*/
/** The context path (ex '/blog' if you are hosting an app on a subpath, like 'mydomain.com/blog') */
@JvmField var contextPath = "/"

/**
* If true, treat '/path' and '/path/' as the same path (default: true).
*/
/** If true, treat '/path' and '/path/' as the same path (default: true). */
@JvmField var ignoreTrailingSlashes = true

/**
* If true, treat '/path//subpath' and '/path/subpath' as the same path (default: false).
*/
/** If true, treat '/path//subpath' and '/path/subpath' as the same path (default: false). */
@JvmField var treatMultipleSlashesAsSingleSlash = false

/**
* If true, treat '/PATH' and '/path' as the same path (default: false).
*/
/** If true, treat '/PATH' and '/path' as the same path (default: false). */
@JvmField var caseInsensitiveRoutes = false
// @formatter:on

Expand Down
5 changes: 1 addition & 4 deletions javalin/src/main/java/io/javalin/config/StaticFilesConfig.kt
Expand Up @@ -17,10 +17,7 @@ import java.util.function.Consumer
*/
class StaticFilesConfig(private val cfg: JavalinConfig) {

/**
* Enable webjars access.
* They will be available at /webjars/name/version/file.ext.
*/
/** Enable webjars access. They will be available at /webjars/name/version/file.ext. */
fun enableWebjars() = add { staticFiles ->
staticFiles.directory = "META-INF/resources/webjars"
staticFiles.headers = mapOf(Header.CACHE_CONTROL to "max-age=31622400")
Expand Down
35 changes: 9 additions & 26 deletions javalin/src/main/java/io/javalin/event/EventManager.kt
Expand Up @@ -22,18 +22,13 @@ class EventManager {
var handlerAddedHandlers = mutableSetOf<Consumer<HandlerMetaInfo>>()
val wsHandlerAddedHandlers = mutableSetOf<Consumer<WsHandlerMetaInfo>>()

/**
* Fires a Javalin Lifecycle Event.
* @param javalinLifecycleEvent the event to send to listeners
*/
/** Fires a Javalin Lifecycle Event to the listeners. */
fun fireEvent(javalinLifecycleEvent: JavalinLifecycleEvent) =
lifecycleHandlers[javalinLifecycleEvent]?.forEach { it.handleEvent() }

/**
* Fires an event telling listeners that a new HTTP handler has been added.
* @param metaInfo the Handler metadata information
*/
/** Fires an event telling listeners that a new HTTP handler has been added.*/
fun fireHandlerAddedEvent(metaInfo: HandlerMetaInfo) = handlerAddedHandlers.onEach { it.accept(metaInfo) }
/** Fires an event telling listeners that a new WebSocket handler has been added. */
fun fireWsHandlerAddedEvent(metaInfo: WsHandlerMetaInfo) = wsHandlerAddedHandlers.onEach { it.accept(metaInfo) }

internal fun addLifecycleEvent(event: JavalinLifecycleEvent, lifecycleEventListener: LifecycleEventListener) {
Expand All @@ -46,34 +41,22 @@ class EventManager {
* The possible Javalin lifecycle event
*/
enum class JavalinLifecycleEvent {
/**
* Event fired when attempting to start the Jetty Webserver
*/
/** Event fired when attempting to start the Jetty Webserver */
SERVER_STARTING,

/**
* Event fired when the Jetty Webserver was started successfully
*/
/** Event fired when the Jetty Webserver was started successfully */
SERVER_STARTED,

/**
* Event fired when an exception occurs while starting the Jetty Webserver
*/
/** Event fired when an exception occurs while starting the Jetty Webserver */
SERVER_START_FAILED,

/**
* Event fired when an exception occurs while stopping the Jetty Webserver
*/
/** Event fired when an exception occurs while stopping the Jetty Webserver */
SERVER_STOP_FAILED,

/**
* Event fired when attempting to stop the Jetty Webserver
*/
/** Event fired when attempting to stop the Jetty Webserver */
SERVER_STOPPING,

/**
* Event fired after the Jetty Webserver was stopped successfully
*/
/** Event fired after the Jetty Webserver was stopped successfully */
SERVER_STOPPED
}

Expand Down
5 changes: 1 addition & 4 deletions javalin/src/main/java/io/javalin/http/Cookie.kt
Expand Up @@ -10,10 +10,7 @@ const val SAME_SITE = "SameSite"
* Value to define the `SameSite` property of a cookie.
*/
enum class SameSite(val value: String) {
/**
* Means that the browser sends the cookie with both cross-site and
* same-site requests.
*/
/** Means that the browser sends the cookie with both cross-site and same-site requests.*/
NONE("$SAME_SITE=None"),

/**
Expand Down
28 changes: 6 additions & 22 deletions javalin/src/main/java/io/javalin/http/HandlerType.kt
Expand Up @@ -16,15 +16,10 @@ import io.javalin.router.JavalinDefaultRouting
*/
enum class HandlerType(val isHttpMethod: Boolean = true) {

/**
* The HTTP GET method requests a representation of the specified resource.
*/
/** The HTTP GET method requests a representation of the specified resource. */
GET,

/**
* The HTTP POST method sends data to the server. The type of the body of the
* request is indicated by the Content-Type header.
*/
/** The HTTP POST method sends data to the server. The type of the body of the request is indicated by the Content-Type header.*/
POST,

/**
Expand All @@ -46,27 +41,16 @@ enum class HandlerType(val isHttpMethod: Boolean = true) {
*/
PATCH,

/**
* The HTTP DELETE request method deletes the specified resource.
*/
/** The HTTP DELETE request method deletes the specified resource. */
DELETE,

/**
* The HTTP HEAD method requests the headers that would be returned if
* the HEAD request's URL was instead requested with the HTTP GET method.
*/
/** The HTTP HEAD method requests the headers that would be returned if the HEAD request's URL was instead requested with the HTTP GET method.*/
HEAD,

/**
* The HTTP TRACE method performs a message loop-back test along the path to
* the target resource, providing a useful debugging mechanism.
*/
/** The HTTP TRACE method performs a message loop-back test along the path to the target resource, providing a useful debugging mechanism.*/
TRACE,

/**
* The HTTP CONNECT method starts two-way communications with the requested
* resource. It can be used to open a tunnel.
*/
/** The HTTP CONNECT method starts two-way communications with the requested resource. It can be used to open a tunnel. */
CONNECT,

/**
Expand Down

0 comments on commit 77f4c5b

Please sign in to comment.