4242import static org .objectweb .asm .Opcodes .ASTORE ;
4343import static org .objectweb .asm .Opcodes .CHECKCAST ;
4444import static org .objectweb .asm .Opcodes .GETSTATIC ;
45+ import static org .objectweb .asm .Opcodes .IFEQ ;
4546import static org .objectweb .asm .Opcodes .INVOKEINTERFACE ;
4647import static org .objectweb .asm .Opcodes .INVOKESTATIC ;
4748import static org .objectweb .asm .Opcodes .INVOKEVIRTUAL ;
@@ -222,14 +223,14 @@ private void processArguments(ClassWriter classWriter, MethodVisitor visitor,
222223
223224 private void setDefaultResponseType (MethodVisitor visitor ) throws Exception {
224225 TypeKind kind = executable .getReturnType ().getKind ();
225- if (kind == TypeKind .VOID ) {
226+ if (kind == TypeKind .VOID && getHttpMethod (). equalsIgnoreCase ( Router . DELETE ) ) {
226227 visitor .visitVarInsn (ALOAD , 1 );
227228 visitor
228229 .visitFieldInsn (GETSTATIC , STATUS_CODE .getInternalName (), "NO_CONTENT" ,
229230 STATUS_CODE .getDescriptor ());
230- Method sendStatusCode = Context .class .getDeclaredMethod ("send " , StatusCode .class );
231- visitor .visitMethodInsn (INVOKEINTERFACE , CTX .getInternalName (), sendStatusCode .getName (),
232- getMethodDescriptor (sendStatusCode ), true );
231+ Method setResponseCode = Context .class .getDeclaredMethod ("setResponseCode " , StatusCode .class );
232+ visitor .visitMethodInsn (INVOKEINTERFACE , CTX .getInternalName (), setResponseCode .getName (),
233+ getMethodDescriptor (setResponseCode ), true );
233234 visitor .visitInsn (POP );
234235 }
235236 }
@@ -238,6 +239,24 @@ private void processReturnType(MethodVisitor visitor) throws Exception {
238239 TypeKind kind = executable .getReturnType ().getKind ();
239240 if (kind == TypeKind .VOID ) {
240241 visitor .visitVarInsn (ALOAD , 1 );
242+ Method isResponseStarted = Context .class .getDeclaredMethod ("isResponseStarted" );
243+ visitor .visitMethodInsn (INVOKEINTERFACE , CTX .getInternalName (), isResponseStarted .getName (),
244+ getMethodDescriptor (isResponseStarted ), true );
245+ Label label0 = new Label ();
246+ visitor .visitJumpInsn (IFEQ , label0 );
247+ visitor .visitVarInsn (ALOAD , 1 );
248+ visitor .visitInsn (ARETURN );
249+ visitor .visitLabel (label0 );
250+ visitor .visitFrame (Opcodes .F_SAME , 0 , null , 0 , null );
251+
252+ visitor .visitVarInsn (ALOAD , 1 );
253+ visitor .visitVarInsn (ALOAD , 1 );
254+ Method getResponseCode = Context .class .getDeclaredMethod ("getResponseCode" );
255+ visitor .visitMethodInsn (INVOKEINTERFACE , CTX .getInternalName (), getResponseCode .getName (),
256+ getMethodDescriptor (getResponseCode ), true );
257+ Method sendStatusCode = Context .class .getDeclaredMethod ("send" , StatusCode .class );
258+ visitor .visitMethodInsn (INVOKEINTERFACE , CTX .getInternalName (), sendStatusCode .getName (),
259+ getMethodDescriptor (sendStatusCode ), true );
241260 } else {
242261 Method wrapper = Primitives .wrapper (kind );
243262 if (wrapper == null ) {
0 commit comments