Ejemplo n.º 1
0
  /* Verify HTTP/1.1 request
   * @exception HttpException problem with the request.
   * @exception IOException problem with the connection.
   */
  private void verifyHTTP_1_1() throws HttpException, IOException {
    // Check Host Field exists
    String host = _request.getField(HttpFields.__Host);
    if (host == null) throw new HttpException(HttpResponse.__400_Bad_Request);

    // check and enable requests transfer encodings.
    String transfer_coding = _request.getField(HttpFields.__TransferEncoding);

    if (transfer_coding != null && transfer_coding.length() > 0) {
      // Handling of codings other than chunking is now
      // the responsibility of handlers, filters or servlets.
      // Thanks to the compression filter, we now don't know if
      // what we can handle here.
      if (transfer_coding.equalsIgnoreCase(HttpFields.__Chunked)
          || StringUtil.endsWithIgnoreCase(transfer_coding, HttpFields.__Chunked))
        _inputStream.setChunking();
      else if (StringUtil.asciiToLowerCase(transfer_coding).indexOf(HttpFields.__Chunked) >= 0)
        throw new HttpException(HttpResponse.__400_Bad_Request);
    }

    // Check input content length can be determined
    int content_length = _request.getIntField(HttpFields.__ContentLength);
    String content_type = _request.getField(HttpFields.__ContentType);
    if (!_inputStream.isChunking()) {
      // If we have a content length, use it
      if (content_length >= 0) _inputStream.setContentLength(content_length);
      // else if we have no content
      else if (content_type == null || content_type.length() == 0) _inputStream.setContentLength(0);
      // else we need a content length
      else {
        // TODO - can't do this check as IE stuff up on
        // a redirect.
        // throw new HttpException(HttpResponse.__411_Length_Required);
        _inputStream.setContentLength(0);
      }
    }

    // Handle Continue Expectations
    String expect = _request.getField(HttpFields.__Expect);
    if (expect != null && expect.length() > 0) {
      if (StringUtil.asciiToLowerCase(expect).equals(HttpFields.__ExpectContinue)) {
        _inputStream.setExpectContinues(_outputStream.getOutputStream());
      } else throw new HttpException(HttpResponse.__417_Expectation_Failed);
    } else if (__2068_Continues
        && _inputStream.available() <= 0
        && (HttpRequest.__PUT.equals(_request.getMethod())
            || HttpRequest.__POST.equals(_request.getMethod()))) {
      // Send continue for RFC 2068 exception
      OutputStream real_out = _outputStream.getOutputStream();
      real_out.write(HttpResponse.__Continue);
      real_out.flush();
    }

    // Persistent unless requested otherwise
    _persistent = !_close;
  }
Ejemplo n.º 2
0
  /* Verify HTTP/1.0 request
   * @exception HttpException problem with the request.
   * @exception IOException problem with the connection.
   */
  private void verifyHTTP_1_0() {
    // Set content length
    int content_length = _request.getIntField(HttpFields.__ContentLength);
    if (content_length >= 0) _inputStream.setContentLength(content_length);
    else if (content_length < 0) {
      // TODO - can't do this check because IE does this after
      // a redirect.
      // Can't have content without a content length
      // String content_type=_request.getField(HttpFields.__ContentType);
      // if (content_type!=null && content_type.length()>0)
      //     throw new HttpException(_HttpResponse.__411_Length_Required);
      _inputStream.setContentLength(0);
    }

    // Check netscape proxy connection - this is not strictly correct.
    if (!_keepAlive
        && HttpFields.__KeepAlive.equalsIgnoreCase(_request.getField(HttpFields.__ProxyConnection)))
      _keepAlive = true;

    // persistent connections in HTTP/1.0 only if requested.
    _persistent = _keepAlive;
  }