Example #1
0
  public void appendHead(Response res) throws IOException {
    if (log.isDebugEnabled())
      log.debug("COMMIT sending headers " + res + " " + res.getMimeHeaders());

    C2BConverter c2b = mc.getConverter();

    outputMsg.reset();
    outputMsg.appendByte(AjpConstants.JK_AJP13_SEND_HEADERS);
    outputMsg.appendInt(res.getStatus());

    String message = null;
    if (org.apache.coyote.Constants.USE_CUSTOM_STATUS_MSG_IN_HEADER
        && HttpMessages.isSafeInHttpHeader(res.getMessage())) {
      message = res.getMessage();
    }
    if (message == null) {
      message = HttpMessages.getMessage(res.getStatus());
    }
    if (message == null) {
      // mod_jk + httpd 2.x fails with a null status message - bug 45026
      message = Integer.toString(res.getStatus());
    }
    tempMB.setString(message);
    c2b.convert(tempMB);
    outputMsg.appendBytes(tempMB);

    // XXX add headers

    MimeHeaders headers = res.getMimeHeaders();
    String contentType = res.getContentType();
    if (contentType != null) {
      headers.setValue("Content-Type").setString(contentType);
    }
    String contentLanguage = res.getContentLanguage();
    if (contentLanguage != null) {
      headers.setValue("Content-Language").setString(contentLanguage);
    }
    long contentLength = res.getContentLengthLong();
    if (contentLength >= 0) {
      headers.setValue("Content-Length").setLong(contentLength);
    }
    int numHeaders = headers.size();
    outputMsg.appendInt(numHeaders);
    for (int i = 0; i < numHeaders; i++) {
      MessageBytes hN = headers.getName(i);
      // no header to sc conversion - there's little benefit
      // on this direction
      outputMsg.appendBytes(hN);

      MessageBytes hV = headers.getValue(i);
      outputMsg.appendBytes(hV);
    }
    mc.getSource().send(outputMsg, mc);
  }
Example #2
0
  /**
   * Has the specified header been set already in this response?
   *
   * @param name Name of the header to check
   */
  @Override
  public boolean containsHeader(String name) {
    // Need special handling for Content-Type and Content-Length due to
    // special handling of these in coyoteResponse
    char cc = name.charAt(0);
    if (cc == 'C' || cc == 'c') {
      if (name.equalsIgnoreCase("Content-Type")) {
        // Will return null if this has not been set
        return (coyoteResponse.getContentType() != null);
      }
      if (name.equalsIgnoreCase("Content-Length")) {
        // -1 means not known and is not sent to client
        return (coyoteResponse.getContentLengthLong() != -1);
      }
    }

    return coyoteResponse.containsHeader(name);
  }
Example #3
0
  /**
   * Close the output buffer. This tries to calculate the response size if the response has not been
   * committed yet.
   *
   * @throws IOException An underlying IOException occurred
   */
  @Override
  public void close() throws IOException {

    if (closed) return;
    if (suspended) return;

    if ((!coyoteResponse.isCommitted()) && (coyoteResponse.getContentLengthLong() == -1)) {
      // If this didn't cause a commit of the response, the final content
      // length can be calculated
      if (!coyoteResponse.isCommitted()) {
        coyoteResponse.setContentLength(bb.getLength());
      }
    }

    doFlush(false);
    closed = true;

    coyoteResponse.finish();
  }