コード例 #1
0
  /**
   * Add to or set a field. If the field is allowed to have multiple values, add will add multiple
   * headers of the same name.
   *
   * @param name the name of the field
   * @param value the value of the field.
   * @exception IllegalArgumentException If the name is a single valued field and already has a
   *     value.
   */
  public void add(Buffer name, Buffer value) throws IllegalArgumentException {
    if (value == null) throw new IllegalArgumentException("null value");

    if (!(name instanceof CachedBuffer)) name = HttpHeaders.CACHE.lookup(name);
    name = name.asImmutableBuffer();

    if (!(value instanceof CachedBuffer)
        && HttpHeaderValues.hasKnownValues(HttpHeaders.CACHE.getOrdinal(name)))
      value = HttpHeaderValues.CACHE.lookup(value);
    value = value.asImmutableBuffer();

    Field field = _names.get(name);
    Field last = null;
    while (field != null) {
      last = field;
      field = field._next;
    }

    // create the field
    field = new Field(name, value);
    _fields.add(field);

    // look for chain to add too
    if (last != null) last._next = field;
    else _names.put(name, field);
  }
コード例 #2
0
    /*
     *
     * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#startRequest(org.eclipse.io.Buffer,
     *      org.eclipse.io.Buffer, org.eclipse.io.Buffer)
     */
    @Override
    public void startRequest(Buffer method, Buffer uri, Buffer version) throws IOException {
      uri = uri.asImmutableBuffer();

      _host = false;
      _expect = false;
      _expect100Continue = false;
      _expect102Processing = false;
      _delayedHandling = false;
      _charset = null;

      if (_request.getTimeStamp() == 0) _request.setTimeStamp(System.currentTimeMillis());
      _request.setMethod(method.toString());

      try {
        _head = false;
        switch (HttpMethods.CACHE.getOrdinal(method)) {
          case HttpMethods.CONNECT_ORDINAL:
            _uri.parseConnect(uri.array(), uri.getIndex(), uri.length());
            break;

          case HttpMethods.HEAD_ORDINAL:
            _head = true;
            // fall through

          default:
            _uri.parse(uri.array(), uri.getIndex(), uri.length());
        }

        _request.setUri(_uri);

        if (version == null) {
          _request.setProtocol(HttpVersions.HTTP_0_9);
          _version = HttpVersions.HTTP_0_9_ORDINAL;
        } else {
          version = HttpVersions.CACHE.get(version);
          if (version == null) throw new HttpException(HttpStatus.BAD_REQUEST_400, null);
          _version = HttpVersions.CACHE.getOrdinal(version);
          if (_version <= 0) _version = HttpVersions.HTTP_1_0_ORDINAL;
          _request.setProtocol(version.toString());
        }
      } catch (Exception e) {
        LOG.debug(e);
        if (e instanceof HttpException) throw (HttpException) e;
        throw new HttpException(HttpStatus.BAD_REQUEST_400, null, e);
      }
    }