// insert the new content:
if(serverSideRendering) {
page.insertAtStartOfBody(toInsert.toString());
} else {
page.insertAtEndOfBody(toInsert.toString());
}
// set the corrected length:
int bytes = page.getBytes().length;
headers.put(HTTP_LENGTH_HEADER, String.valueOf(bytes));