Source:
<code>public void sendResponse(final Exchange exchange, final Response response) { Response responseToSend = response; if (isTransparentBlockwiseHandlingEnabled()) { BlockOption requestBlock2 = exchange.getRequest().getOptions().getBlock2(); BlockOption responseBlock2 = response.getOptions().getBlock2(); if (requestBlock2 != null && requestBlock2.getNum() > 0) { if (responseBlock2 != null) { if (requestBlock2.getNum() != responseBlock2.getNum()) { LOGGER.log( Level.WARNING, "resource [{0}] implementation error, peer requested block {1} but resource returned block {2}", new Object[]{exchange.getRequest().getURI(), requestBlock2.getNum(), responseBlock2.getNum()}); responseToSend = Response.createResponse(exchange.getRequest(), ResponseCode.INTERNAL_SERVER_ERROR); responseToSend.setType(response.getType()); responseToSend.setMID(response.getMID()); } } else if (response.hasBlock(requestBlock2)) { Block2BlockwiseStatus.crop(responseToSend, requestBlock2); } else { responseToSend = Response.createResponse(exchange.getRequest(), ResponseCode.BAD_OPTION); responseToSend.setType(response.getType()); responseToSend.setMID(response.getMID()); responseToSend.getOptions().setBlock2(requestBlock2); } } else if (requiresBlockwise(exchange, response, requestBlock2)) { KeyUri key = getKey(exchange, response); <START> Block2BlockwiseStatus status = getOutboundBlock2Status(key, exchange, response); <END> responseToSend = status.getNextResponseBlock(); if (status.isComplete()) { LOGGER.log(Level.FINE, "block2 transfer of response finished after first block: {0}", status); clearBlock2Status(key); } else { LOGGER.log(Level.FINE, "block2 transfer of response started: {0}", status); addBlock2CleanUpObserver(responseToSend, key); } } BlockOption block1 = exchange.getBlock1ToAck(); if (block1 != null) { exchange.setBlock1ToAck(null); responseToSend.getOptions().setBlock1(block1); } } exchange.setCurrentResponse(responseToSend); lower().sendResponse(exchange, responseToSend); }</code><technical_language>Is case start a fresh new block2 transfer ? If I face kind of question block1, do if a running block2 transfer for resource/endpoint</technical_language>

Target:
public void sendResponse(final Exchange exchange, final Response response) { Response responseToSend = response; if (isTransparentBlockwiseHandlingEnabled()) { BlockOption requestBlock2 = exchange.getRequest().getOptions().getBlock2(); BlockOption responseBlock2 = response.getOptions().getBlock2(); if (requestBlock2 != null && requestBlock2.getNum() > 0) { if (responseBlock2 != null) { if (requestBlock2.getNum() != responseBlock2.getNum()) { LOGGER.log( Level.WARNING, "resource [{0}] implementation error, peer requested block {1} but resource returned block {2}", new Object[]{exchange.getRequest().getURI(), requestBlock2.getNum(), responseBlock2.getNum()}); responseToSend = Response.createResponse(exchange.getRequest(), ResponseCode.INTERNAL_SERVER_ERROR); responseToSend.setType(response.getType()); responseToSend.setMID(response.getMID()); } } else if (response.hasBlock(requestBlock2)) { Block2BlockwiseStatus.crop(responseToSend, requestBlock2); } else { responseToSend = Response.createResponse(exchange.getRequest(), ResponseCode.BAD_OPTION); responseToSend.setType(response.getType()); responseToSend.setMID(response.getMID()); responseToSend.getOptions().setBlock2(requestBlock2); } } else if (requiresBlockwise(exchange, response, requestBlock2)) { KeyUri key = getKey(exchange, response); Block2BlockwiseStatus status = getOutboundBlock2Status(key, exchange, response); BlockOption block2 = requestBlock2 != null ? requestBlock2 : new BlockOption(preferredBlockSzx, false, 0); responseToSend = status.getNextResponseBlock(block2); if (status.isComplete()) { LOGGER.log(Level.FINE, "block2 transfer of response finished after first block: {0}", status); clearBlock2Status(key); } else { LOGGER.log(Level.FINE, "block2 transfer of response started: {0}", status); addBlock2CleanUpObserver(responseToSend, key); } } BlockOption block1 = exchange.getBlock1ToAck(); if (block1 != null) { exchange.setBlock1ToAck(null); responseToSend.getOptions().setBlock1(block1); } } exchange.setCurrentResponse(responseToSend); lower().sendResponse(exchange, responseToSend); }