PrimeIntellect/SWE-rebench-V2-Filtered-Easy-Verified huggingface dataset:
Repository: tipsy/javalin (kotlin)
Issue: Context: Expose handlerType
**Describe the feature**
It would be great to expose the handler type in the context. Right now it is shielded by being set to `internal` in kotlin.

**Additional context**
I am currently trying to add APM agent instrumentation support for Javalin for the Elastic APM agent. I need access to that handler type to properly set the name of a span, as I would like to include the HTTP method. My idea is to name the span like `BEFORE /my-url`, `GET /my-url` and `AFTER my-url` - but that would require to have access to the `handlerType.name()` value.

Just switching this from internal in the context might already help.
Pull request description: Closes #1263

Patch:
diff --git a/javalin/src/main/java/io/javalin/http/Context.kt b/javalin/src/main/java/io/javalin/http/Context.kt
index 82ab1c2c4..102773cd1 100644
--- a/javalin/src/main/java/io/javalin/http/Context.kt
+++ b/javalin/src/main/java/io/javalin/http/Context.kt
@@ -477,5 +477,8 @@ open class Context(@JvmField val req: HttpServletRequest, @JvmField val res: Htt
 
     /** Gets a list of all the [splat] values. */
     fun splats(): List<String> = Collections.unmodifiableList(splatList)
+
+    /** Gets the handler type of the current handler */
+    fun handlerType() : HandlerType = handlerType
 }
 


Test patch:
diff --git a/javalin/src/test/java/io/javalin/TestContextHandlerType.java b/javalin/src/test/java/io/javalin/TestContextHandlerType.java
new file mode 100644
index 000000000..d871d27ed
--- /dev/null
+++ b/javalin/src/test/java/io/javalin/TestContextHandlerType.java
@@ -0,0 +1,30 @@
+/*
+ * Javalin - https://javalin.io
+ * Copyright 2021 David Åse
+ * Licensed under Apache 2.0: https://github.com/tipsy/javalin/blob/master/LICENSE
+ */
+package io.javalin;
+
+import io.javalin.http.HandlerType;
+import io.javalin.testing.TestUtil;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TestContextHandlerType {
+
+    @Test
+    public void testHandlerTypeCanBeAccessedInContext() {
+        TestUtil.test(Javalin.create(), (app, http) -> {
+            List<HandlerType> handlerTypes = new ArrayList<>();
+            app.before(ctx -> handlerTypes.add(ctx.handlerType()));
+            app.after(ctx -> handlerTypes.add(ctx.handlerType()));
+            app.get("/", ctx -> handlerTypes.add(ctx.handlerType()));
+
+            Assertions.assertThat(http.get("/").getStatus()).isEqualTo(200);
+            Assertions.assertThat(handlerTypes).containsExactly(HandlerType.BEFORE, HandlerType.GET, HandlerType.AFTER);
+        });
+    }
+}