4646import static org .objectweb .asm .Opcodes .INVOKEINTERFACE ;
4747import static org .objectweb .asm .Opcodes .INVOKESTATIC ;
4848import static org .objectweb .asm .Opcodes .INVOKEVIRTUAL ;
49+ import static org .objectweb .asm .Opcodes .POP ;
4950import static org .objectweb .asm .Type .getMethodDescriptor ;
5051import static org .objectweb .asm .Type .getType ;
5152
@@ -184,6 +185,8 @@ private void apply(ClassWriter writer, String moduleInternalName, String lambdaN
184185 /** Arguments. */
185186 processArguments (writer , apply , moduleInternalName , registry );
186187
188+ setDefaultResponseType (apply );
189+
187190 /** Invoke. */
188191 apply .visitMethodInsn (INVOKEVIRTUAL , owner .getInternalName (), methodName , methodDescriptor ,
189192 false );
@@ -227,6 +230,20 @@ private void processArguments(ClassWriter classWriter, MethodVisitor visitor,
227230 }
228231 }
229232
233+ private void setDefaultResponseType (MethodVisitor visitor ) throws Exception {
234+ TypeKind kind = executable .getReturnType ().getKind ();
235+ if (kind == TypeKind .VOID && getHttpMethod ().equalsIgnoreCase (Router .DELETE )) {
236+ visitor .visitVarInsn (ALOAD , 1 );
237+ visitor
238+ .visitFieldInsn (GETSTATIC , STATUS_CODE .getInternalName (), "NO_CONTENT" ,
239+ STATUS_CODE .getDescriptor ());
240+ Method setResponseCode = Context .class .getDeclaredMethod ("setResponseCode" , StatusCode .class );
241+ visitor .visitMethodInsn (INVOKEINTERFACE , CTX .getInternalName (), setResponseCode .getName (),
242+ getMethodDescriptor (setResponseCode ), true );
243+ visitor .visitInsn (POP );
244+ }
245+ }
246+
230247 private void processReturnType (MethodVisitor visitor ) throws Exception {
231248 TypeKind kind = executable .getReturnType ().getKind ();
232249 if (kind == TypeKind .VOID ) {
@@ -242,15 +259,14 @@ private void processReturnType(MethodVisitor visitor) throws Exception {
242259 visitor .visitFrame (Opcodes .F_SAME , 0 , null , 0 , null );
243260
244261 visitor .visitVarInsn (ALOAD , 1 );
245- visitor
246- .visitFieldInsn (GETSTATIC , STATUS_CODE .getInternalName (), "NO_CONTENT" ,
247- STATUS_CODE .getDescriptor ());
262+ visitor .visitVarInsn (ALOAD , 1 );
263+ Method getResponseCode = Context .class .getDeclaredMethod ("getResponseCode" );
264+ visitor .visitMethodInsn (INVOKEINTERFACE , CTX .getInternalName (), getResponseCode .getName (),
265+ getMethodDescriptor (getResponseCode ), true );
248266 Method sendStatusCode = Context .class .getDeclaredMethod ("send" , StatusCode .class );
249267 visitor .visitMethodInsn (INVOKEINTERFACE , CTX .getInternalName (), sendStatusCode .getName (),
250268 getMethodDescriptor (sendStatusCode ), true );
251-
252269 } else {
253-
254270 Method wrapper = Primitives .wrapper (kind );
255271 if (wrapper == null ) {
256272 TypeDefinition returnType = getReturnType ();
0 commit comments