if (!response.isCommitted()) { // Send the connector a request for commit. The connector should // then validate the headers, send them (using sendHeaders) and // set the filters accordingly.
response.action(ActionCode.COMMIT, null);
}
publicvoid sendAck() throws IOException { // It possible that the protocol configuration is changed between the // request being received and the first read of the body. That could led // to multiple calls to this method so ensure the ACK is only sent once. if (!response.isCommitted() && !ackSent) {
ackSent = true;
socketWrapper.write(isBlocking(), Constants.ACK_BYTES, 0, Constants.ACK_BYTES.length); if (flushBuffer(true)) { thrownew IOException(sm.getString("iob.failedwrite.ack"));
}
}
}
// Write status code int status = response.getStatus(); switch (status) { case200:
write(Constants._200_BYTES); break; case400:
write(Constants._400_BYTES); break; case404:
write(Constants._404_BYTES); break; default:
write(status);
}
headerBuffer.put(Constants.SP);
// The reason phrase is optional but the space before it is not. Skip // sending the reason phrase. Clients should ignore it (RFC 7230) and it // just wastes bytes.
/** *Thismethodwillwritethecontentsofthespecifiedmessagebytesbuffertotheoutputstream,without *filtering.Thismethodismeanttobeusedtowritetheresponseheader. * *@parammbdatatobewritten
*/ privatevoid write(MessageBytes mb) { if (mb.getType() != MessageBytes.T_BYTES) {
mb.toBytes();
ByteChunk bc = mb.getByteChunk(); // Need to filter out CTLs excluding TAB. ISO-8859-1 and UTF-8 // values will be OK. Strings using other encodings may be // corrupted. byte[] buffer = bc.getBuffer(); for (int i = bc.getOffset(); i < bc.getLength(); i++) { // byte values are signed i.e. -128 to 127 // The values are used unsigned. 0 to 31 are CTLs so they are // filtered (apart from TAB which is 9). 127 is a control (DEL). // The values 128 to 255 are all OK. Converting those to signed // gives -128 to -1. if ((buffer[i] > -1 && buffer[i] <= 31 && buffer[i] != 9) || buffer[i] == 127) {
buffer[i] = ' ';
}
}
}
write(mb.getByteChunk());
}
/** *Thismethodwillwritethecontentsofthespecifiedbytechunktotheoutputstream,withoutfiltering.This *methodismeanttobeusedtowritetheresponseheader. * *@parambcdatatobewritten
*/ privatevoid write(ByteChunk bc) { // Writing the byte chunk to the output buffer int length = bc.getLength();
checkLengthBeforeWrite(length);
headerBuffer.put(bc.getBytes(), bc.getStart(), length);
}
// Writing the byte chunk to the output buffer
headerBuffer.put(b);
}
/** *Thismethodwillwritethespecifiedintegertotheoutputstream.Thismethodismeanttobeusedtowritethe *responseheader. * *@paramvaluedatatobewritten
*/ privatevoid write(int value) { // From the Tomcat 3.3 HTTP/1.0 connector
String s = Integer.toString(value); int len = s.length();
checkLengthBeforeWrite(len); for (int i = 0; i < len; i++) { char c = s.charAt(i);
headerBuffer.put((byte) c);
}
}
/** *Checkstoseeifthereisenoughspaceinthebuffertowritetherequestednumberofbytes.
*/ privatevoid checkLengthBeforeWrite(int length) { // "+ 4": BZ 57509. Reserve space for CR/LF/COLON/SP characters that // are put directly into the buffer following this write operation. if (headerBuffer.position() + length + 4 > headerBuffer.capacity()) { thrownew HeadersTooLargeException(sm.getString("iob.responseheadertoolarge.error"));
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.