【问题标题】:How to reset header buffer in Lucee?如何在 Lucee 中重置标头缓冲区?
【发布时间】:2019-01-14 08:10:35
【问题描述】:

我正在尝试为我在 Lucee 4.5 上运行的 ColdBox 应用程序编写一个单元测试,使用 为一个包含 cfhtmlhead() 调用的函数。

不幸的是,通常使用该函数附加到 HTML 输出的 <head> 部分的字符串被附加到单元测试的输出中,导致测试失败。

cfhtmlhead() 的输出显然被写入了一个特殊的缓冲区。根据blog post,可以清除该缓冲区。此处显示的示例函数如下所示:

function clearHeaderBuffer() {
  local.out = getPageContext().getOut();
  while (getMetaData(local.out).getName() is "coldfusion.runtime.NeoBodyContent") {
    local.out = local.out.getEnclosingWriter();
  }
  local.method = local.out.getClass().getDeclaredMethod("initHeaderBuffer", arrayNew(1));
  local.method.setAccessible(true);
  local.method.invoke(local.out, arrayNew(1));
}

虽然这篇博文是为 Adob​​e ColdFusion 编写的,但它在 Lucee 中的工作方式显然不同。 通过转储local.out,我看到该对象有一个方法resetHTMLHead()。但是调用该方法似乎也不起作用(即使相关的getHTMLHead() 方法从cfhtmlhead() 调用输出字符串)。

那么,如何在 Lucee 中重置头缓冲区?

【问题讨论】:

    标签: testbox unit-testing cfml lucee testbox


    【解决方案1】:

    我通过查看 Lucee 来源找到了答案。那里有buffer is accessed via getRootOut().getHTMLHead()

    所以清除头缓冲区的代码归结为:

    function clearHeaderBuffer() {
      getPageContext().getRootOut().resetHTMLHead();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-03
      • 2011-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多