|
Revision 580, 1.5 kB
(checked in by aimbert, 3 years ago)
|
|
add a path filter t the AtomStream:
- the AtomInject plugin receives a PUT request on a given path ("$put_path") with the content of an entry.
- the AtomStream plugin receives a GET request on another path ("$get_path/atom-stream.xml") (the arg 'since' is still allowed)
$put_path and $get_path can be '/' or '/a' or '/a/b', ....
then the AtomStream plugin produces a result filtered like this:
GET /atom-stream.xml returns everything ('/' or '/a' or '/a/b')
GET /a/atom-stream.xml returns the entries put with '/a' or '/a/b'
GET /a/b/atom-stream.xml returns the entries put with '/a/b'
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 1 | package Perlbal::Plugin::AtomInject; |
|---|
| 2 | |
|---|
| 3 | use Perlbal; |
|---|
| 4 | use strict; |
|---|
| 5 | use warnings; |
|---|
| 6 | |
|---|
| 7 | our @subs; # subscribers |
|---|
| 8 | |
|---|
| 9 | # called when we're being added to a service |
|---|
| 10 | sub register { |
|---|
| 11 | my ($class, $svc) = @_; |
|---|
| 12 | |
|---|
| 13 | $svc->{enable_put} = 1; |
|---|
| 14 | |
|---|
| 15 | $svc->register_hook('AtomInject', 'handle_put', sub { |
|---|
| 16 | my Perlbal::ClientHTTP $self = shift; |
|---|
| 17 | my Perlbal::HTTPHeaders $hds = $self->{req_headers}; |
|---|
| 18 | return 0 unless $hds; |
|---|
| 19 | |
|---|
| 20 | return $self->send_response(400, "Invalid method") |
|---|
| 21 | unless $hds->request_method eq "PUT"; |
|---|
| 22 | |
|---|
| 23 | my $uri = $hds->request_uri; |
|---|
| 24 | return $self->send_response(400, "Invalid uri") unless $uri =~ /^\//; |
|---|
| 25 | $self->{scratch}{path} = $uri; |
|---|
| 26 | |
|---|
| 27 | # now abort the normal handle_put processing... |
|---|
| 28 | return 1; |
|---|
| 29 | }); |
|---|
| 30 | |
|---|
| 31 | $svc->register_hook('AtomInject', 'put_writeout', sub { |
|---|
| 32 | my Perlbal::ClientHTTP $self = shift; |
|---|
| 33 | return 1 if $self->{content_length_remain}; |
|---|
| 34 | |
|---|
| 35 | my $data = join("", map { $$_ } @{$self->{read_buf}}); |
|---|
| 36 | |
|---|
| 37 | # reset our input buffer |
|---|
| 38 | $self->{read_buf} = []; |
|---|
| 39 | $self->{read_ahead} = 0; |
|---|
| 40 | |
|---|
| 41 | my $rv = eval { Perlbal::Plugin::AtomStream->InjectFeed(\$data, $self->{scratch}{path}); }; |
|---|
| 42 | return $self->send_response(200); |
|---|
| 43 | }); |
|---|
| 44 | |
|---|
| 45 | return 1; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | # called when we're no longer active on a service |
|---|
| 49 | sub unregister { |
|---|
| 50 | my ($class, $svc) = @_; |
|---|
| 51 | return 1; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | # called when we are loaded |
|---|
| 55 | sub load { |
|---|
| 56 | return 1; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | # called for a global unload |
|---|
| 60 | sub unload { |
|---|
| 61 | return 1; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | 1; |
|---|