java - Should ServletResponse isCommitted Always Be Checked Before Modifying The Response -


the title speaks itself, valuable check iscommitted() on type servletresponse? particular example in using filter following if user isn't authorized perform action (csrf checks specific):

if (!httpresp.iscommitted()) {     httpresp.senderror(httpservletresponse.sc_unauthorized); } 

in case, feels overkill i've checked response. filter @ top of chain, there should nothing before commit response (let alone allow filter chain continue if did), can't feel assumption in name of defensive programming shouldn't making. feel it's practice check status of response.

so, of being said, valuable check response @ point in time? , maybe extend further, practice check every time response modified? in case, can hardly find reason support other exception being thrown when csrf token not match (assuming happen in attack scenario).

in general, based on when code executed know response has not been committed. not add check everywhere.

some places add it:-

  • a piece of library code might called in various different contexts
  • exception handling code might reached before or after response has been comitted

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -