Esempio n. 1
0
 public void setLongContentLength(long len) {
   // Protect from setting after committed as default handling
   // of a servlet HEAD request ALWAYS sets _content length, even
   // if the getHandling committed the response!
   if (isCommitted() || isIncluding()) return;
   _contentLength = len;
   _fields.putLongField(HttpHeader.CONTENT_LENGTH.toString(), len);
 }
Esempio n. 2
0
  @Override
  public void setContentLength(int len) {
    // Protect from setting after committed as default handling
    // of a servlet HEAD request ALWAYS sets _content length, even
    // if the getHandling committed the response!
    if (isCommitted() || isIncluding()) return;

    long written = _out.getWritten();
    if (written > len)
      throw new IllegalArgumentException(
          "setContentLength(" + len + ") when already written " + written);

    _contentLength = len;
    _fields.putLongField(HttpHeader.CONTENT_LENGTH.toString(), len);

    if (_contentLength > 0) {
      try {
        closeIfAllContentWritten(written);
      } catch (IOException e) {
        throw new RuntimeIOException(e);
      }
    }
  }