line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright Infomation |
2
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
3
|
|
|
|
|
|
|
# Author : Dr. Ahmed Amin Elsheshtawy, Ph.D. |
4
|
|
|
|
|
|
|
# Website: https://github.com/mewsoft/Nile, http://www.mewsoft.com |
5
|
|
|
|
|
|
|
# Email : mewsoft@cpan.org, support@mewsoft.com |
6
|
|
|
|
|
|
|
# Copyrights (c) 2014-2015 Mewsoft Corp. All rights reserved. |
7
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
8
|
|
|
|
|
|
|
package Nile::HTTP::Request; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.55'; |
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:MEWSOFT'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=pod |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=encoding utf8 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Nile::HTTP::Request - The HTTP request manager. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# get app context |
24
|
|
|
|
|
|
|
$app = $self->app; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# get request instance which extends CGI::Simple |
27
|
|
|
|
|
|
|
$request = $app->request; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$email = $request->param("email"); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$value = $request->cookie("username"); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Nile::HTTP::Request - The HTTP request manager. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The http request is available as a shared object extending the L<CGI::Simple> module. This means that all methods supported |
38
|
|
|
|
|
|
|
by L<CGI::Simple> is available with the additions to these few methods: |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
base_url |
41
|
|
|
|
|
|
|
abs_url |
42
|
|
|
|
|
|
|
url_path |
43
|
|
|
|
|
|
|
is_ajax |
44
|
|
|
|
|
|
|
is_post |
45
|
|
|
|
|
|
|
is_get |
46
|
|
|
|
|
|
|
is_head |
47
|
|
|
|
|
|
|
is_put |
48
|
|
|
|
|
|
|
is_delete |
49
|
|
|
|
|
|
|
is_patch |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
You access the request object by $self->app->request. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
1
|
|
4
|
use Nile::Base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
56
|
1
|
|
|
1
|
|
6405
|
use MooseX::NonMoose; |
|
1
|
|
|
|
|
746
|
|
|
1
|
|
|
|
|
5
|
|
57
|
|
|
|
|
|
|
extends 'CGI::Simple'; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#Methods: HEAD, POST, GET, PUT, DELETE, PATCH |
60
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
61
|
|
|
|
|
|
|
sub is_ajax { |
62
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
63
|
0
|
0
|
0
|
|
|
|
if (exists $ENV{HTTP_X_REQUESTED_WITH} && lc($ENV{HTTP_X_REQUESTED_WITH}) eq 'xmlhttprequest') { |
64
|
0
|
|
|
|
|
|
return 1; |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
return 0; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
69
|
0
|
|
|
0
|
0
|
|
sub is_post {lc(shift->request_method) eq "post";} |
70
|
0
|
|
|
0
|
0
|
|
sub is_get {lc(shift->request_method) eq "get";} |
71
|
0
|
|
|
0
|
0
|
|
sub is_head {lc(shift->request_method) eq "head";} |
72
|
0
|
|
|
0
|
0
|
|
sub is_put {lc(shift->request_method) eq "put";} |
73
|
0
|
|
|
0
|
0
|
|
sub is_delete {lc(shift->request_method) eq "delete";} |
74
|
0
|
|
|
0
|
0
|
|
sub is_patch {lc(shift->request_method) eq "patch";} |
75
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
76
|
|
|
|
|
|
|
sub base_url { |
77
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
78
|
0
|
|
|
|
|
|
my $url = $self->url(); |
79
|
0
|
|
|
|
|
|
my $script = $self->url(-relative=>1); |
80
|
0
|
|
|
|
|
|
$url =~ s/\Q$script\E//; |
81
|
0
|
0
|
|
|
|
|
$url = "$url/" if $url !~ m{/$}; |
82
|
0
|
|
|
|
|
|
return $url; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
85
|
|
|
|
|
|
|
sub abs_url { |
86
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
87
|
0
|
|
|
|
|
|
my $url = $self->url(-absolute=>1); |
88
|
0
|
|
|
|
|
|
my $script = $self->url(-relative=>1); |
89
|
0
|
|
|
|
|
|
$url =~ s/\Q$script\E//; |
90
|
0
|
0
|
|
|
|
|
$url = "$url/" if $url !~ m|/$|; |
91
|
0
|
|
|
|
|
|
return $url; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
94
|
|
|
|
|
|
|
sub url_path { |
95
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
96
|
0
|
|
|
|
|
|
my $route = ""; |
97
|
0
|
|
|
|
|
|
my ($path, $script_name) = $self->script_name =~ m#(.*)/(.*)$#; |
98
|
0
|
|
0
|
|
|
|
my ($request_uri, $params) = split(/\?/, ($ENV{REQUEST_URI} || $self->app->env->{REQUEST_URI} || '')); |
99
|
0
|
0
|
|
|
|
|
if ($request_uri) { |
100
|
0
|
|
|
|
|
|
$route = $request_uri; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# remove path part from the route |
103
|
0
|
|
|
|
|
|
$route =~ s/^$path//; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#remove script name from route |
106
|
0
|
|
|
|
|
|
$route =~ s/$script_name\/?$//; |
107
|
|
|
|
|
|
|
} |
108
|
0
|
0
|
|
|
|
|
$route = "$route/" if $route !~ m|/$|; |
109
|
0
|
|
|
|
|
|
return $route; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=pod |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 Bugs |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This project is available on github at L<https://github.com/mewsoft/Nile>. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 HOMEPAGE |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Nile>. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SOURCE |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Source repository is at L<https://github.com/mewsoft/Nile>. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SEE ALSO |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
See L<Nile> for details about the complete framework. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 AUTHOR |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Ahmed Amin Elsheshtawy, اØÙ
د اÙ
Ù٠اÙششتاÙÙ <mewsoft@cpan.org> |
134
|
|
|
|
|
|
|
Website: http://www.mewsoft.com |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy اØÙ
د اÙ
Ù٠اÙششتاÙÙ mewsoft@cpan.org, support@mewsoft.com, |
139
|
|
|
|
|
|
|
L<https://github.com/mewsoft/Nile>, L<http://www.mewsoft.com> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |