[pve-devel] [PATCH 3/9] HTTPServer.pm: allow to set baseuri when creating the class
Fabian Grünbichler
f.gruenbichler at proxmox.com
Tue Jan 10 15:45:20 CET 2017
noticed that there are a couple RE matching for $baseuri without
escaping (but with ! as delimiter ;)) - maybe we could clean it up as
well?
On Tue, Jan 10, 2017 at 11:55:20AM +0100, Dietmar Maurer wrote:
> Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
> ---
> PVE/HTTPServer.pm | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/PVE/HTTPServer.pm b/PVE/HTTPServer.pm
> index 5c55fa5..ce7c707 100755
> --- a/PVE/HTTPServer.pm
> +++ b/PVE/HTTPServer.pm
> @@ -47,10 +47,10 @@ my $known_methods = {
> DELETE => 1,
> };
>
> -my $baseuri = "/api2";
> -
> sub split_abs_uri {
> - my ($abs_uri) = @_;
> + my ($self, $abs_uri) = @_;
> +
> + my $baseuri = $self->{baseuri};
>
like the cookie methods, this looks more like a helper to me (with no
callers outside of HTTPServer, so this could even be made into a private
sub?).
would prefer if it had two params for base_uri and abs_uri instead.
> my ($format, $rel_uri) = $abs_uri =~ m/^\Q$baseuri\E\/+([a-z][a-z0-9]+)(\/.*)?$/;
> $rel_uri = '/' if !$rel_uri;
> @@ -734,7 +734,7 @@ sub handle_api2_request {
> eval {
> my $r = $reqstate->{request};
>
> - my ($rel_uri, $format) = split_abs_uri($path);
> + my ($rel_uri, $format) = $self->split_abs_uri($path);
>
> my $formatter = get_formatter($format);
>
> @@ -975,6 +975,8 @@ sub handle_spice_proxy_request {
> sub handle_request {
> my ($self, $reqstate, $auth, $method, $path) = @_;
>
> + my $baseuri = $self->{baseuri};
not sure if we need to do this? $self->{baseuri} is already short, and
it's accessed read-only anyway?
> +
> eval {
> my $r = $reqstate->{request};
>
> @@ -1235,6 +1237,7 @@ sub unshift_read_header {
> }
>
> my $pveclientip = $r->header('PVEClientIP');
> + my $baseuri = $self->{baseuri};
see above
>
> # fixme: how can we make PVEClientIP header trusted?
> if ($self->{trusted_env} && $pveclientip) {
> @@ -1262,7 +1265,7 @@ sub unshift_read_header {
> my $cookie = $r->header('Cookie');
> my $ticket = $self->extract_auth_cookie($cookie);
>
> - my ($rel_uri, $format) = split_abs_uri($path);
> + my ($rel_uri, $format) = $self->split_abs_uri($path);
> if (!$format) {
> $self->error($reqstate, HTTP_NOT_IMPLEMENTED, "no such uri");
> return;
> @@ -1652,6 +1655,7 @@ sub new {
> my $self = bless { %args }, $class;
>
> $self->{cookie_name} //= 'PVEAuthCookie';
> + $self->{baseuri} //= "/api2";
>
> PVE::REST::set_base_handler_class($self->{base_handler_class});
>
> --
> 2.1.4
>
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
More information about the pve-devel
mailing list