[pve-devel] [PATCH 3/9] HTTPServer.pm: allow to set baseuri when creating the class

Dietmar Maurer dietmar at proxmox.com
Tue Jan 10 11:55:20 CET 2017


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};
 
     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};
+
     eval {
 	my $r = $reqstate->{request};
 	
@@ -1235,6 +1237,7 @@ sub unshift_read_header {
 		}
 
 		my $pveclientip = $r->header('PVEClientIP');
+		my $baseuri = $self->{baseuri};
 
 		# 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



More information about the pve-devel mailing list