1 | #! perl # optional depends=tcp |
1 | #! perl # optional depends=tcp |
2 | |
2 | |
3 | # http server on base port |
3 | # http server |
4 | |
|
|
5 | use Coro::AnyEvent; |
|
|
6 | |
4 | |
7 | sub send { |
5 | sub send { |
8 | my $self = $_[0]; |
6 | my $self = $_[0]; |
9 | |
7 | |
10 | $self->{wbuf} .= $_[1]; |
8 | $self->{wbuf} .= $_[1]; |
… | |
… | |
118 | } |
116 | } |
119 | } |
117 | } |
120 | |
118 | |
121 | our $DETECTOR = ext::tcp::register http => 64, sub { |
119 | our $DETECTOR = ext::tcp::register http => 64, sub { |
122 | # regex avoids conflict with websockets, which use /ws |
120 | # regex avoids conflict with websockets, which use /ws |
123 | m{^(?:(?i)GET|HEAD|OPTIONS) \ (?: [^/] | /[^w] | /w[^s] /ws[^\ ] ) }x |
121 | m{^(?i:GET|HEAD|OPTIONS) \ (?! (?i:http://[^/]+)? /ws \ ) }x |
124 | }, sub { |
122 | }, sub { |
125 | my $self = bless { |
123 | my $self = bless { |
126 | id => $_[0], |
124 | id => $_[0], |
127 | fh => $_[1], |
125 | fh => $_[1], |
128 | rbuf => $_[2], |
126 | rbuf => $_[2], |