Is this the correct way to return 204 "No Content" using Spring?

Eduardo Guimaraes :

I'm trying to delete a resource setting http status NO_CONTENT using Weblogic and the response takes 30 seconds to complete. Am i misusing Spring or is there a bug in Weblogic?

I've tried this on Weblogic 12.2.1.0.0 using Spring 5.0.12. The request is completed, the resource is removed but the client waits for 30 seconds (browser TTFB) after that. This seems to be a kind of timeout.

As a workaround, we could return http status OK.

@DeleteMapping(value = "/{id}")
public ResponseEntity<Void> delete(@PathVariable("id") Long id) {
    useCase.remove(id);
    return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

I expected the client to immediately receive the response, but it waits 30 seconds.

Karol Dowbecki :

Comparing to 200 response your 204 response has no Content-Length header. Try adding it manually to see if it helps with your application server handling empty response body:

return ResponseEntity.noContent().header("Content-Length", "0").build();

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=158007&siteId=1