使用 Mojo 时如何省略路由的 headers?
How can I omit the headers for a route when using Mojo?
Mojo 似乎想在响应中添加 headers。在给定上下文 object 的情况下,是否有任何方法可以抑制 headers?
$r->get('/')->to( cb => sub {
my $c = shift;
# No headers for this response
} );
就我而言,我使用的是 Mojo::Server::CGI
. You can see the problems on line 29 and on line 35
return undef if $self->nph && !_write($res, 'get_start_line_chunk');
...
return undef unless _write($res, 'get_header_chunk');
你可以通过破坏内部结构来解决这个问题,
$c->res->content->_headers->{header_buffer} = '';
$c->res->{start_buffer} = '';
但更好的方法是检测是否已将任何内容写入 STDOUT,如果是则抑制整个请求,
# We withhold headers if anything has written to
# STDOUT. This is neccessary because some scripts, in-transition
# to Mojo will still use `print`, and output headers
if ( tell(*STDOUT) != 0 ) {
return undef;
}
那是我发表时所做的事情 Mojo::Server::CGI::LegacyMigrate
Mojo 似乎想在响应中添加 headers。在给定上下文 object 的情况下,是否有任何方法可以抑制 headers?
$r->get('/')->to( cb => sub {
my $c = shift;
# No headers for this response
} );
就我而言,我使用的是 Mojo::Server::CGI
. You can see the problems on line 29 and on line 35
return undef if $self->nph && !_write($res, 'get_start_line_chunk');
...
return undef unless _write($res, 'get_header_chunk');
你可以通过破坏内部结构来解决这个问题,
$c->res->content->_headers->{header_buffer} = '';
$c->res->{start_buffer} = '';
但更好的方法是检测是否已将任何内容写入 STDOUT,如果是则抑制整个请求,
# We withhold headers if anything has written to
# STDOUT. This is neccessary because some scripts, in-transition
# to Mojo will still use `print`, and output headers
if ( tell(*STDOUT) != 0 ) {
return undef;
}
那是我发表时所做的事情 Mojo::Server::CGI::LegacyMigrate