【发布时间】:2018-10-22 06:21:43
【问题描述】:
这个问题的动机是这里的答案: What to do with errors when streaming the body of an Http request
在这种情况下,我已经编写了一个 HTTP 200 OK 标头,如果出现错误,我需要通过编写一个跟踪标头来修改此标头,该标头表示在编写一个错误 之后成功标头。
我有这个 Node.js 代码:
const writeResponse = function(file: string, socket: Socket){
socket.write([
'HTTP/1.1 200 OK',
'Content-Type: text/javascript; charset=UTF-8',
'Content-Encoding: UTF-8',
'Accept-Ranges: bytes',
'Connection: keep-alive',
].join('\n') + '\n\n');
getStream(file)
.pipe(socket)
.once('error', function (e: any) {
// there was an error
// how can I write trail headers here ?
s.write('some bad shit happened\n')
});
}
如何在响应中写一个有用的跟踪标头,以便浏览器很好地显示?
我认为这是跟踪标头的相关规范: https://www.rfc-editor.org/rfc/rfc2616#section-14.40
我认为它们应该被称为“尾随标题”,但无论如何。
【问题讨论】:
标签: http http-headers httpresponse http-error