[Jifty-commit] jifty branch, plack-rebased, updated. 6f6a051060caedee02e6209cec5f07bd67518cd8
Jifty commits
jifty-commit at lists.jifty.org
Sun Feb 7 03:04:09 EST 2010
The branch, plack-rebased has been updated
via 6f6a051060caedee02e6209cec5f07bd67518cd8 (commit)
via 34606a9e42fc12312dd8ee984761800253118e43 (commit)
via 49857cd369af48f44589fe49b7126e63256deb4a (commit)
from 5c91a68cc2a029f86d491c709bf9d0ef1bcd5040 (commit)
Summary of changes:
Changelog | 3 +++
Makefile.PL | 3 +--
lib/Jifty/Dispatcher.pm | 4 ++--
lib/Jifty/I18N.pm | 1 +
lib/Jifty/Plugin/Compat.pm | 4 ++++
lib/Jifty/Request.pm | 3 ++-
lib/Jifty/Util.pm | 6 +++++-
lib/Jifty/Web.pm | 5 +++--
t/09-url.t | 18 ++++++++++++++----
t/Jifty.pm | 2 +-
t/TestApp/t/02-dispatch-http.t | 21 ---------------------
t/TestApp/t/02-dispatch-https.t | 23 -----------------------
t/TestApp/t/02-dispatch-protocol.t | 19 +++++++++++++++++++
13 files changed, 55 insertions(+), 57 deletions(-)
delete mode 100644 t/TestApp/t/02-dispatch-http.t
delete mode 100644 t/TestApp/t/02-dispatch-https.t
create mode 100644 t/TestApp/t/02-dispatch-protocol.t
- Log -----------------------------------------------------------------
commit 49857cd369af48f44589fe49b7126e63256deb4a
Author: Chia-liang Kao <clkao at clkao.org>
Date: Sun Feb 7 14:43:36 2010 +0800
provide apache->method in compat plugin.
diff --git a/lib/Jifty/Plugin/Compat.pm b/lib/Jifty/Plugin/Compat.pm
index d1d1d94..e449d52 100644
--- a/lib/Jifty/Plugin/Compat.pm
+++ b/lib/Jifty/Plugin/Compat.pm
@@ -98,6 +98,10 @@ sub header_out {
Jifty->web->response->header( $key, $val );
}
+sub method {
+ Jifty->web->request->method;
+}
+
sub content_type {
my $class = shift;
Jifty->web->response->content_type( @_ );
commit 34606a9e42fc12312dd8ee984761800253118e43
Author: Chia-liang Kao <clkao at clkao.org>
Date: Sun Feb 7 16:03:01 2010 +0800
Plack::Request is now part of Plack.
diff --git a/Makefile.PL b/Makefile.PL
index 264eb2c..5ecb500 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -70,8 +70,7 @@ requires('Module::Refresh');
requires('Module::ScanDeps');
requires('Object::Declare' => '0.13');
requires('Params::Validate');
-requires('Plack' => '0.99_01'); # Plack::Loader Plack::Test Plack::Util Plack::Builder
-requires('Plack::Request');
+requires('Plack' => '0.99_01'); # Plack::Loader Plack::Test Plack::Util Plack::Builder Plack::Request
requires('Plack::Middleware::Deflater');
requires('Scalar::Defer' => '0.12');
requires('Shell::Command');
commit 6f6a051060caedee02e6209cec5f07bd67518cd8
Author: Chia-liang Kao <clkao at clkao.org>
Date: Sun Feb 7 16:03:20 2010 +0800
Remove all remaining %ENV munging.
diff --git a/Changelog b/Changelog
index 39fb4a0..ecc1ee3 100644
--- a/Changelog
+++ b/Changelog
@@ -16,6 +16,9 @@ INCOMPATABILITIES
* Printing to STDOUT deprecated. Use outs, outs_raw, or
Jifty->web->response->body() instead.
+ * munging with the %ENV hash is no longer supported. Use
+ Jifty->web->request->env instead.
+
-----------------------------------
Jifty 0.91117 - November 17th, 2009
-----------------------------------
diff --git a/lib/Jifty/Dispatcher.pm b/lib/Jifty/Dispatcher.pm
index 078c8e8..c1c4644 100644
--- a/lib/Jifty/Dispatcher.pm
+++ b/lib/Jifty/Dispatcher.pm
@@ -970,7 +970,7 @@ Returns true if the current request is under SSL.
sub _match_https {
my $self = shift;
$self->log->debug("Matching request against HTTPS");
- return exists $ENV{HTTPS} ? 1 : 0;
+ return Jifty->web->request->secure;
}
=head2 _match_http
@@ -982,7 +982,7 @@ Returns true if the current request is not under SSL.
sub _match_http {
my $self = shift;
$self->log->debug("Matching request against HTTP");
- return exists $ENV{HTTPS} ? 0 : 1;
+ return !Jifty->web->request->secure;
}
sub _match_plugin {
diff --git a/lib/Jifty/I18N.pm b/lib/Jifty/I18N.pm
index a8e484d..8b897a6 100644
--- a/lib/Jifty/I18N.pm
+++ b/lib/Jifty/I18N.pm
@@ -198,6 +198,7 @@ sub get_language_handle {
}
}
+ # I18N::LangTags::Detect wants these for detecting
local $ENV{REQUEST_METHOD} = Jifty->web->request->method
if Jifty->web->request;
local $ENV{HTTP_ACCEPT_LANGUAGE} = Jifty->web->request->header("Accept-Language") || ""
diff --git a/lib/Jifty/Request.pm b/lib/Jifty/Request.pm
index 5fed154..edb596f 100644
--- a/lib/Jifty/Request.pm
+++ b/lib/Jifty/Request.pm
@@ -21,6 +21,7 @@ has 'uploads' => (is => 'rw', isa => 'HashRef');
has 'headers' => (is => 'rw', isa => 'HTTP::Headers', default => sub { HTTP::Headers->new });
has 'uri' => (is => 'rw', isa => 'URI', default => sub { URI->new('http:///') });
has 'cookies' => (is => 'rw', isa => 'HashRef', default => sub { {} } );
+has 'scheme' => (is => "rw", isa => "Str", default => sub { 'http' });
sub address { $_[0]->env->{REMOTE_ADDR} }
sub remote_host { $_[0]->env->{REMOTE_HOST} }
@@ -32,7 +33,6 @@ sub user { $_[0]->env->{REMOTE_USER} }
sub request_uri { $_[0]->env->{REQUEST_URI} }
sub path_info { $_[0]->env->{PATH_INFO} }
sub script_name { $_[0]->env->{SCRIPT_NAME} }
-sub scheme { $_[0]->env->{'psgi.url_scheme'} }
sub secure { $_[0]->scheme eq 'https' }
sub body { $_[0]->env->{'psgi.input'} }
sub input { $_[0]->env->{'psgi.input'} }
@@ -167,6 +167,7 @@ sub promote {
headers => $req->headers,
parameters => $req->parameters->mixed,
uploads => $req->uploads->mixed,
+ scheme => $req->scheme,
uri => $req->uri,
cookies => $req->cookies,
actions => {},
diff --git a/lib/Jifty/Util.pm b/lib/Jifty/Util.pm
index dbeb5fc..d2916cc 100644
--- a/lib/Jifty/Util.pm
+++ b/lib/Jifty/Util.pm
@@ -349,7 +349,11 @@ sub reference_to_data {
my $id = $obj->id;
# probably a file extension, from the REST rewrite
- my $extension = $ENV{HTTP_ACCEPT} =~ /^\w+$/ ? ".$ENV{HTTP_ACCEPT}" : '';
+ my $extension = '';
+ if (Jifty->web->request &&
+ Jifty->web->request->env->{HTTP_ACCEPT} =~ m/^\w+$/) {
+ $extension = '.'.Jifty->web->request->env->{HTTP_ACCEPT};
+ }
return {
jifty_model_reference => 1,
diff --git a/lib/Jifty/Web.pm b/lib/Jifty/Web.pm
index b645636..956a92d 100644
--- a/lib/Jifty/Web.pm
+++ b/lib/Jifty/Web.pm
@@ -128,7 +128,7 @@ sub url {
# Try to get a host out of the environment, useful in remote testing.
# The code is a little hairy because there's no guarantee these
# environment variables have all the information.
- if (my $http_host_env = $ENV{HTTP_HOST}) {
+ if (Jifty->web->request && (my $http_host_env = Jifty->web->request->uri->host)) {
# Explicit flag needed because URI->new("noscheme") is structurally
# different from URI->new("http://smth"). Clunky, but works.
my $dirty;
@@ -743,6 +743,7 @@ sub redirect {
# We should replicate that here.
$request->path( URI::Escape::uri_unescape( $page->url ) );
$request->method("GET"); # ..effectively.
+ $request->scheme($self->request->scheme);
$request->continuation($self->request->continuation);
my $cont = Jifty::Continuation->new(
request => $request,
@@ -1512,6 +1513,6 @@ Indicates whether the current request was made using SSL.
=cut
-sub is_ssl { $ENV{HTTPS} }
+sub is_ssl { Jifty->web->request && Jifty->web->request->secure }
1;
diff --git a/t/09-url.t b/t/09-url.t
index f3175ad..a8b52c8 100644
--- a/t/09-url.t
+++ b/t/09-url.t
@@ -2,6 +2,7 @@
use warnings;
use strict;
+use Plack::Test;
=head1 DESCRIPTION
@@ -14,8 +15,17 @@ use Jifty::Test tests => 5;
like(Jifty->web->url, qr{^http://localhost:\d+/$}, 'basic call works');
like(Jifty->web->url(path => 'foo/bar'), qr{^http://localhost:\d+/foo/bar$}, 'path works');
like(Jifty->web->url(path => '/foo/bar'), qr{^http://localhost:\d+/foo/bar$}, 'path with leading slash works');
-
-$ENV{HTTP_HOST} = 'example.com';
-is(Jifty->web->url, 'http://example.com/', 'setting hostname via env works');
-is(Jifty->web->url(path => 'foo/bar'), 'http://example.com/foo/bar', 'hostname via env and path works');
+Jifty::Handler->add_trigger(
+ have_request => sub {
+ is(Jifty->web->url, 'http://example.com/', 'setting hostname via request works');
+ is(Jifty->web->url(path => 'foo/bar'), 'http://example.com/foo/bar', 'hostname via requestand path works');
+ });
+
+test_psgi
+ app => Jifty->handler->psgi_app,
+ client => sub {
+ my $cb = shift;
+ my $req = HTTP::Request->new(GET => "http://example.com/foo/bar");
+ my $res = $cb->($req);
+ };
diff --git a/t/Jifty.pm b/t/Jifty.pm
index 16542d9..fc07d39 100644
--- a/t/Jifty.pm
+++ b/t/Jifty.pm
@@ -16,7 +16,7 @@ use Test::Base::Filter -Base;
sub request_from_webform {
my $form = shift;
my $r = Jifty::Request->new->from_webform(%$form);
- delete $r->{$_} for qw(env headers parameters cookies);
+ delete $r->{$_} for qw(env headers parameters cookies scheme);
return $r;
}
diff --git a/t/TestApp/t/02-dispatch-http.t b/t/TestApp/t/02-dispatch-http.t
deleted file mode 100644
index 0ea01cf..0000000
--- a/t/TestApp/t/02-dispatch-http.t
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/env perl
-use warnings;
-use strict;
-
-# Just in case
-BEGIN { delete $ENV{HTTPS}; }
-
-use Jifty::Test::Dist tests => 5;
-use Jifty::Test::WWW::Mechanize;
-
-my $server = Jifty::Test->make_server;
-
-isa_ok($server, 'Jifty::TestServer');
-
-my $URL = $server->started_ok;
-my $mech = Jifty::Test::WWW::Mechanize->new();
-
-$mech->get_ok("$URL/dispatch/protocol", "Got /dispatch/protocol");
-$mech->content_contains("NOT HTTPS");
-$mech->content_contains("normal");
-
diff --git a/t/TestApp/t/02-dispatch-https.t b/t/TestApp/t/02-dispatch-https.t
deleted file mode 100644
index f3d1522..0000000
--- a/t/TestApp/t/02-dispatch-https.t
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env perl
-use warnings;
-use strict;
-
-BEGIN { $ENV{HTTPS} = 1; }
-
-use Jifty::Test::Dist tests => 6;
-use Jifty::Test::WWW::Mechanize;
-
-my $server = Jifty::Test->make_server;
-
-isa_ok($server, 'Jifty::TestServer');
-
-my $URL = $server->started_ok;
-my $mech = Jifty::Test::WWW::Mechanize->new();
-#$URL =~ s/http:/https:/;
-
-$mech->get_ok("$URL/dispatch/protocol", "Got /dispatch/protocol");
-$mech->content_contains("HTTPS");
-$mech->content_lacks("NOT");
-$mech->content_contains("normal");
-
-
diff --git a/t/TestApp/t/02-dispatch-protocol.t b/t/TestApp/t/02-dispatch-protocol.t
new file mode 100644
index 0000000..3bf6c68
--- /dev/null
+++ b/t/TestApp/t/02-dispatch-protocol.t
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+use Jifty::Test::Dist tests => 7;
+use Test::WWW::Mechanize::PSGI;
+
+my $mech = Test::WWW::Mechanize::PSGI->new(
+ app => Jifty->handler->psgi_app );
+
+$mech->get_ok("http://example.com/dispatch/protocol", "Got /dispatch/protocol");
+$mech->content_contains("NOT HTTPS");
+$mech->content_contains("normal");
+
+$mech->get_ok("https://example.com/dispatch/protocol", "Got /dispatch/protocol");
+$mech->content_contains("HTTPS");
+$mech->content_lacks("NOT");
+$mech->content_contains("normal");
+
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list