MCPcopy Index your code
hub / github.com/apache/tomcat / prepareResponse

Method prepareResponse

java/org/apache/coyote/ajp/AjpProcessor.java:911–991  ·  view source on GitHub ↗

When committing the response, we have to validate the set of headers, as well as setup the response filters.

()

Source from the content-addressed store, hash-verified

909 * When committing the response, we have to validate the set of headers, as well as setup the response filters.
910 */
911 @Override
912 protected final void prepareResponse() throws IOException {
913
914 response.setCommitted(true);
915
916 // Responses with certain status codes and/or methods are not permitted to include a response body.
917 int statusCode = response.getStatus();
918 if (statusCode < 200 || statusCode == 204 || statusCode == 205 || statusCode == 304 ||
919 Method.HEAD.equals(request.getMethod())) {
920 // No entity body
921 swallowResponse = true;
922 }
923
924 // Prepare special headers
925 MimeHeaders headers = response.getMimeHeaders();
926 String contentType = response.getContentType();
927 if (contentType != null) {
928 headers.setValue("Content-Type").setString(contentType);
929 }
930 String contentLanguage = response.getContentLanguage();
931 if (contentLanguage != null) {
932 headers.setValue("Content-Language").setString(contentLanguage);
933 }
934 long contentLength = response.getContentLengthLong();
935 if (contentLength >= 0) {
936 headers.setValue("Content-Length").setLong(contentLength);
937 }
938
939 tmpMB.recycle();
940 responseMsgPos = -1;
941
942 int numHeaders = headers.size();
943 boolean needAjpMessageHeader = true;
944 while (needAjpMessageHeader) {
945 // Write AJP message header
946 responseMessage.reset();
947 responseMessage.appendByte(Constants.JK_AJP13_SEND_HEADERS);
948
949 // Write HTTP response line
950 responseMessage.appendInt(statusCode);
951 // Reason phrase is optional but mod_jk + httpd 2.x fails with a null
952 // reason phrase - bug 45026
953 tmpMB.setString(Integer.toString(response.getStatus()));
954 responseMessage.appendBytes(tmpMB);
955
956 // Start headers
957 responseMessage.appendInt(numHeaders);
958
959 needAjpMessageHeader = false;
960
961 for (int i = 0; i < numHeaders; i++) {
962 try {
963 // Write headers
964 MessageBytes hN = headers.getName(i);
965 int hC = Constants.getResponseAjpIndex(hN.toString());
966 if (hC > 0) {
967 responseMessage.appendInt(hC);
968 } else {

Callers 1

doWriteMethod · 0.45

Calls 15

setValueMethod · 0.95
sizeMethod · 0.95
getNameMethod · 0.95
getResponseAjpIndexMethod · 0.95
toStringMethod · 0.95
getValueMethod · 0.95
removeHeaderMethod · 0.95
setCommittedMethod · 0.80
getContentLanguageMethod · 0.80
appendByteMethod · 0.80
appendIntMethod · 0.80
appendBytesMethod · 0.80

Tested by

no test coverage detected