예제 #1
0
    public void startResponse(Buffer version, int status, Buffer reason) {
      request = false;
      f0 = version.toString();
      f1 = Integer.toString(status);
      f2 = reason == null ? null : reason.toString();

      fields = new HttpFields();
      hdr = new String[9];
      val = new String[9];

      messageCompleted = false;
      headerCompleted = false;
    }
예제 #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);
      }
    }
예제 #3
0
    public void startRequest(Buffer tok0, Buffer tok1, Buffer tok2) {
      try {
        request = true;
        h = -1;
        hdr = new String[9];
        val = new String[9];
        f0 = tok0.toString();
        f1 = new String(tok1.array(), tok1.getIndex(), tok1.length(), StringUtil.__UTF8);
        if (tok2 != null) f2 = tok2.toString();
        else f2 = null;

        fields = new HttpFields();
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
      }

      messageCompleted = false;
      headerCompleted = false;
    }
    public void onFrame(byte flags, byte opcode, Buffer buffer) {
      try {
        byte[] array = buffer.array();

        if (opcode == 0) {
          if (_websocket instanceof WebSocket.OnTextMessage)
            ((WebSocket.OnTextMessage) _websocket).onMessage(buffer.toString(StringUtil.__UTF8));
        } else {
          if (_websocket instanceof WebSocket.OnBinaryMessage)
            ((WebSocket.OnBinaryMessage) _websocket)
                .onMessage(array, buffer.getIndex(), buffer.length());
        }
      } catch (Throwable th) {
        LOG.warn(th);
      }
    }
예제 #5
0
 public void parsedHeader(Buffer name, Buffer value) {
   hdr[++h] = name.toString(StringUtil.__ISO_8859_1);
   val[h] = value.toString(StringUtil.__ISO_8859_1);
 }
예제 #6
0
    /*
     * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#parsedHeaderValue(org.eclipse.io.Buffer)
     */
    @Override
    public void parsedHeader(Buffer name, Buffer value) {
      int ho = HttpHeaders.CACHE.getOrdinal(name);
      switch (ho) {
        case HttpHeaders.HOST_ORDINAL:
          // TODO check if host matched a host in the URI.
          _host = true;
          break;

        case HttpHeaders.EXPECT_ORDINAL:
          value = HttpHeaderValues.CACHE.lookup(value);
          switch (HttpHeaderValues.CACHE.getOrdinal(value)) {
            case HttpHeaderValues.CONTINUE_ORDINAL:
              _expect100Continue = _generator instanceof HttpGenerator;
              break;

            case HttpHeaderValues.PROCESSING_ORDINAL:
              _expect102Processing = _generator instanceof HttpGenerator;
              break;

            default:
              String[] values = value.toString().split(",");
              for (int i = 0; values != null && i < values.length; i++) {
                CachedBuffer cb = HttpHeaderValues.CACHE.get(values[i].trim());
                if (cb == null) _expect = true;
                else {
                  switch (cb.getOrdinal()) {
                    case HttpHeaderValues.CONTINUE_ORDINAL:
                      _expect100Continue = _generator instanceof HttpGenerator;
                      break;
                    case HttpHeaderValues.PROCESSING_ORDINAL:
                      _expect102Processing = _generator instanceof HttpGenerator;
                      break;
                    default:
                      _expect = true;
                  }
                }
              }
          }
          break;

        case HttpHeaders.ACCEPT_ENCODING_ORDINAL:
        case HttpHeaders.USER_AGENT_ORDINAL:
          value = HttpHeaderValues.CACHE.lookup(value);
          break;

        case HttpHeaders.CONTENT_TYPE_ORDINAL:
          value = MimeTypes.CACHE.lookup(value);
          _charset = MimeTypes.getCharsetFromContentType(value);
          break;

        case HttpHeaders.CONNECTION_ORDINAL:
          // looks rather clumsy, but the idea is to optimize for a single valued header
          switch (HttpHeaderValues.CACHE.getOrdinal(value)) {
            case -1:
              {
                String[] values = value.toString().split(",");
                for (int i = 0; values != null && i < values.length; i++) {
                  CachedBuffer cb = HttpHeaderValues.CACHE.get(values[i].trim());

                  if (cb != null) {
                    switch (cb.getOrdinal()) {
                      case HttpHeaderValues.CLOSE_ORDINAL:
                        _responseFields.add(
                            HttpHeaders.CONNECTION_BUFFER, HttpHeaderValues.CLOSE_BUFFER);
                        _generator.setPersistent(false);
                        break;

                      case HttpHeaderValues.KEEP_ALIVE_ORDINAL:
                        if (_version == HttpVersions.HTTP_1_0_ORDINAL)
                          _responseFields.add(
                              HttpHeaders.CONNECTION_BUFFER, HttpHeaderValues.KEEP_ALIVE_BUFFER);
                        break;
                    }
                  }
                }
                break;
              }
            case HttpHeaderValues.CLOSE_ORDINAL:
              _responseFields.put(HttpHeaders.CONNECTION_BUFFER, HttpHeaderValues.CLOSE_BUFFER);
              _generator.setPersistent(false);
              break;

            case HttpHeaderValues.KEEP_ALIVE_ORDINAL:
              if (_version == HttpVersions.HTTP_1_0_ORDINAL)
                _responseFields.put(
                    HttpHeaders.CONNECTION_BUFFER, HttpHeaderValues.KEEP_ALIVE_BUFFER);
              break;
          }
      }

      _requestFields.add(name, value);
    }