示例#1
0
  /**
   * Set the content type for this Response.
   *
   * @param type The new content type
   */
  @Override
  public void setContentType(String type) {

    if (isCommitted()) {
      return;
    }

    // Ignore any call from an included servlet
    if (included) {
      return;
    }

    if (type == null) {
      coyoteResponse.setContentType(null);
      return;
    }

    String[] m = MEDIA_TYPE_CACHE.parse(type);
    if (m == null) {
      // Invalid - Assume no charset and just pass through whatever
      // the user provided.
      coyoteResponse.setContentTypeNoCharset(type);
      return;
    }

    coyoteResponse.setContentTypeNoCharset(m[0]);

    if (m[1] != null) {
      // Ignore charset if getWriter() has already been called
      if (!usingWriter) {
        coyoteResponse.setCharacterEncoding(m[1]);
        isCharacterEncodingSet = true;
      }
    }
  }
示例#2
0
 /**
  * Set internal fields for special header names. Called from set/addHeader. Return true if the
  * header is special, no need to set the header.
  */
 private boolean checkSpecialHeader(String name, String value) {
   // XXX Eliminate redundant fields !!!
   // ( both header and in special fields )
   if (name.equalsIgnoreCase("Content-Type")) {
     setContentType(value);
     return true;
   }
   if (name.equalsIgnoreCase("Content-Length")) {
     try {
       long cL = Long.parseLong(value);
       setContentLength(cL);
       return true;
     } catch (NumberFormatException ex) {
       // Do nothing - the spec doesn't have any "throws"
       // and the user might know what he's doing
       return false;
     }
   }
   return false;
 }
示例#3
0
 /**
  * Set internal fields for special header names. Called from set/addHeader. Return true if the
  * header is special, no need to set the header.
  */
 private boolean checkSpecialHeader(String name, String value) {
   // XXX Eliminate redundant fields !!!
   // ( both header and in special fields )
   if (name.equalsIgnoreCase("Content-Type")) {
     setContentType(value);
     return true;
   }
   if (name.equalsIgnoreCase("Content-Length")) {
     try {
       int cL = Integer.parseInt(value);
       setContentLength(cL);
       return true;
     } catch (NumberFormatException ex) {
       // Do nothing - the spec doesn't have any "throws"
       // and the user might know what he's doing
       return false;
     }
   }
   if (name.equalsIgnoreCase("Content-Language")) {
     // XXX XXX Need to construct Locale or something else
   }
   return false;
 }