File: IIS7KeepAliveFix.pm

package info (click to toggle)
libplack-perl 1.0033-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,472 kB
  • ctags: 406
  • sloc: perl: 5,259; python: 6; makefile: 4
file content (54 lines) | stat: -rw-r--r-- 1,155 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package Plack::Middleware::IIS7KeepAliveFix;

use strict;
use parent 'Plack::Middleware';
use Plack::Util;

sub call {
    my($self, $env) = @_;
        # Fixes buffer being cut off on redirect when keep-alive is active
        my $res  = $self->app->($env);

        Plack::Util::response_cb($res, sub {
            my $res = shift;
            if ($res->[0] =~ m!^30[123]$! ) {
                Plack::Util::header_remove($res->[1], 'Content-Length');
                Plack::Util::header_remove($res->[1], 'Content-Type');
               return sub{ my $chunk; return unless defined $chunk; return ''; };
            }

            return;
        });

}

1;
__END__

=head1 NAME

Plack::Middleware::IIS7KeepAliveFix - fixes buffer being cut off on redirect when keep-alive is active on IIS.

=head1 SYNOPSIS

  # in your app.psgi
  use Plack::Builder;

  builder {
    enable "IIS7KeepAliveFix";
    $app;
  };

  # Or from the command line
  plackup -s FCGI -e 'enable "IIS7KeepAliveFix"' /path/to/app.psgi

=head1 DESCRIPTION

This middleware fixes buffer being cut off on redirect when keep-alive is active on IIS7.

=head1 AUTHORS

KnowZeroX

=cut