Exemplo n.º 1
0
 @Override
 public void addIntHeader(String name, int value) {
   if (!isIncluding()) {
     _fields.add(name, Integer.toString(value));
     if (HttpHeader.CONTENT_LENGTH.is(name)) _contentLength = value;
   }
 }
Exemplo n.º 2
0
 @Override
 public void setIntHeader(String name, int value) {
   if (!isIncluding()) {
     _fields.putLongField(name, value);
     if (HttpHeader.CONTENT_LENGTH.is(name)) _contentLength = value;
   }
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
  @Override
  public void addHeader(String name, String value) {
    if (isIncluding()) {
      if (name.startsWith(SET_INCLUDE_HEADER_PREFIX))
        name = name.substring(SET_INCLUDE_HEADER_PREFIX.length());
      else return;
    }

    _fields.add(name, value);
    if (HttpHeader.CONTENT_LENGTH.is(name)) {
      if (value == null) _contentLength = -1l;
      else _contentLength = Long.parseLong(value);
    }
  }
  @Override
  public void onHeaders(Response response) {
    HttpFields headers = response.getHeaders();
    long length = headers.getLongField(HttpHeader.CONTENT_LENGTH.asString());
    if (length > maxLength)
      response.abort(new IllegalArgumentException("Buffering capacity exceeded"));

    String contentType = headers.get(HttpHeader.CONTENT_TYPE);
    if (contentType != null) {
      String charset = "charset=";
      int index = contentType.toLowerCase(Locale.ENGLISH).indexOf(charset);
      if (index > 0) {
        String encoding = contentType.substring(index + charset.length());
        // Sometimes charsets arrive with an ending semicolon
        index = encoding.indexOf(';');
        if (index > 0) encoding = encoding.substring(0, index);
        this.encoding = encoding;
      }
    }
  }
Exemplo n.º 6
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);
      }
    }
  }