AS2Secure 从 headers 中删除 multipart/signed content-type

AS2Secure drops multipart/signed content-type from headers

我正在尝试使用 PHP 库 AS2Secure 接收 AS2 MDN。消息到达并解码得很好,但是当响应发出时,它会从 Content-Type.

中剥离主要的 "multipart/signed" 值

例如,像这样的东西应该在主 header 中以指定多部分消息:

Content-Type: multipart/signed; boundary="----=_Part_8f23d0b4-8a42-4946-9928-4d12d9f7fc66.63"; protocol="application/pkcs7-signature"; micalg=SHA1

但是,当对多部分消息的响应消失时,我只在主要 headers 中看到这个:

Content-Type: text/html; charset=UTF-8

这会在远程服务器中触发一个错误,它希望消息将其 content-type 指定为多部分。

我在 AS2MDN.php 中跟踪了多部分 content-type 的剥离到这段代码:

// TODO : replace with futur AS2MimePart to separate content from header
if (strpos($content, "\n\n") !== false) $content = substr($content, strpos($content, "\n\n") + 2);

如果我删除此代码,缺少的 Content-Type: multipart/signed 行会显示在 body 中,但 Content-Type: text/html 仍会显示在 header 中。

有什么想法吗?

这是由于 PHP Laravel 框架(处理应用程序的路由)在输出期间覆盖 headers 造成的。

AS2server.php 中的 handle() 方法中更改此代码:

ob_end_clean();
// send headers
foreach ($mdn->getHeaders() as $key => $value) {
    $header = str_replace(["\r", "\n", "\r\n"], '', $key . ': ' . $value);
    header($header);
}

// output MDN
echo $mdn->getContent();

...此 Laravel 友好代码:

$headers = [];

foreach ($mdn->getHeaders() as $key => $value) {
    $headers[str_replace(["\r", "\n", "\r\n"], '', $key)] = str_replace(["\r", "\n", "\r\n"], '', $value);
}

return \Response::make($mdn->getContent(), 200, $headers); // Use native Laravel response.

...解决了问题!