public synchronized void flush () {
    try {

      if (request_object != null) {
        //System.err.println("request object: " + request_object);
        request_object.write (this);
        request_object = null;
      }
      if (index > 0) {
        // Possibly pad request.
        int pad = pad (index - request_index);
        if (pad != 0)
          skip (pad);
        try {
          out.write (buffer, 0, index);
        } catch (IOException ex) {
          handle_exception (ex);
        }
        index = 0;
        request_index = 0;
      }

      out.flush ();

    } catch (IOException ex) {
      handle_exception (ex);
    }
  }