Implement $r->read and remove hacky workaround.
Patch by exor674.
diffs (128 lines):
diff -r 9a3953d15315 -r 87b564b441db cgi-bin/DW/Controller/Interface/AtomAPI.pm
--- a/cgi-bin/DW/Controller/Interface/AtomAPI.pm Tue Mar 08 15:20:16
2011 +0800
+++ b/cgi-bin/DW/Controller/Interface/AtomAPI.pm Thu Mar 10 11:27:54
2011 +0800
@@ -44,7 +44,7 @@ sub ok {
my ( $message, $status, $content_type ) = @_;
return DW::Template->render_string(
$message,
- { status => $status || DW::Request->get->OK,
+ { status => $status || DW::Request->get->HTTP_OK,
content_type => $content_type || "application/atom+xml",
no_sitescheme => 1,
}
@@ -259,14 +259,13 @@ sub _create_entry {
my $r = DW::Request->get;
my ( $buff, $len, $entry );
- $buff = $r->pnote( "input" ) if $LJ::T_PASS_INPUT_THROUGH_REQUEST;
unless ( $buff ) {
# check length
$len = $r->header_in( "Content-length" );
return err( "Content is too long", $r->HTTP_BAD_REQUEST )
if $len > $LJ::MAX_ATOM_UPLOAD;
-
+
# read the content
$r->read( $buff, $len );
}
@@ -436,7 +435,6 @@ sub _edit_entry {
my ( $buff, $len, $atom_entry );
- $buff = $r->pnote( "input" ) if $LJ::T_PASS_INPUT_THROUGH_REQUEST;
unless ( $buff ) {
# check length
diff -r 9a3953d15315 -r 87b564b441db cgi-bin/DW/Request/Standard.pm
--- a/cgi-bin/DW/Request/Standard.pm Tue Mar 08 15:20:16 2011 +0800
+++ b/cgi-bin/DW/Request/Standard.pm Thu Mar 10 11:27:54 2011 +0800
@@ -40,6 +40,8 @@ use fields (
# we have to parse these out ourselves
'uri',
'querystring',
+
+ 'read_offset'
);
# creates a new DW::Request object, based on what type of server environment we
@@ -57,6 +59,7 @@ sub new {
$self->{uri} = $self->{req}->uri;
$self->{notes} = {};
$self->{pnotes} = {};
+ $self->{read_offset} = 0;
# now stick ourselves as the primary request ...
unless ( $DW::Request::cur_req ) {
@@ -264,9 +267,29 @@ sub print {
return;
}
+# FIXME(dre): this may not be the most efficient way but is
+# totally fine when we are just using this for tests.
+# We *may* need to revisit this if we use this for serving pages
+# IMPORTANT: Do not pull out $_[1] to a variable in this sub
sub read {
- my DW::Request::Standard $self = shift;
- confess "Reading not implemented.\n";
+ my DW::Request::Standard $self = $_[0];
+ die "missing required arguments" if scalar( @_ ) < 3;
+
+ my $prefix = '';
+ if ( exists $_[3] ) {
+ die "Negative offsets not allowed" if $_[3] < 0;
+ $prefix = substr( $_[1],0,$_[3] );
+ }
+
+ die "Length cannot be negative" if $_[2] < 0;
+ my $ov = substr( $self->content, $self->{read_offset}, $_[2] );
+
+ # Given $_[1] and whatever was passed in as the first argument are the
+ # same exact scalar this will set *that* variable too.
+ $_[1] = $prefix . $ov;
+
+ $self->{read_offset} += length( $ov );
+ return length( $ov );
}
# return the internal Standard request object... in this case, we are
diff -r 9a3953d15315 -r 87b564b441db cgi-bin/LJ/Test.pm
--- a/cgi-bin/LJ/Test.pm Tue Mar 08 15:20:16 2011 +0800
+++ b/cgi-bin/LJ/Test.pm Thu Mar 10 11:27:54 2011 +0800
@@ -204,6 +204,11 @@ sub routing_request {
LJ::start_request();
my $req = HTTP::Request->new( $method => $uri );
+
+ if ( $opts{content} ) {
+ $req->content( $opts{content} );
+ $req->header( 'Content-Length', length( $opts{content} ) );
+ }
$opts{setup_http_request}->($req) if $opts{setup_http_request};
diff -r 9a3953d15315 -r 87b564b441db t/atom-post.t
--- a/t/atom-post.t Tue Mar 08 15:20:16 2011 +0800
+++ b/t/atom-post.t Thu Mar 10 11:27:54 2011 +0800
@@ -12,9 +12,6 @@ use XML::Atom::Category;
use XML::Atom::Category;
use XML::Atom::Feed;
use DW::Routing;
-
-# workaround for non-implented read() sub in DW::Request::Standard
-$LJ::T_PASS_INPUT_THROUGH_REQUEST = 1;
# so that entries can be posted to community journals
$LJ::EVERYONE_VALID = 1;
@@ -40,8 +37,11 @@ sub do_request {
my %routing_data = ();
$routing_data{username} = $user_subdomain if $user_subdomain;
+ my $input = delete $data->{input};
+
$r = routing_request( $uri,
method => $method,
+ content => $input,
setup_http_request => sub {
if ( $authenticate ) {
$api->username( $remote->username );
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog