]> git.proxmox.com Git - pve-http-server.git/commitdiff
proxy request: forward json content type and parameters
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 6 Jun 2023 13:08:48 +0000 (15:08 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 7 Jun 2023 11:16:54 +0000 (13:16 +0200)
instead of always trying to encode them as x-www-form-urlencoded

Acked-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/PVE/APIServer/AnyEvent.pm

index 8be2347511bc394d88759c55dd1db0c0f3caef26..59da46619392aae6ecb02717c6fac439edf7c064 100644 (file)
@@ -745,11 +745,16 @@ sub proxy_request {
        my $content;
 
        if  ($method eq 'POST' || $method eq 'PUT') {
-           $headers->{'Content-Type'} = 'application/x-www-form-urlencoded';
-           # use URI object to format application/x-www-form-urlencoded content.
-           my $url = URI->new('http:');
-           $url->query_form(%$params);
-           $content = $url->query;
+           if ($reqstate->{request}->header('Content-Type') =~ 'application/json') {
+               $headers->{'Content-Type'} = 'application/json';
+               $content = encode_json($params);
+           } else {
+               $headers->{'Content-Type'} = 'application/x-www-form-urlencoded';
+               # use URI object to format application/x-www-form-urlencoded content.
+               my $url = URI->new('http:');
+               $url->query_form(%$params);
+               $content = $url->query;
+           }
            if (defined($content)) {
                $headers->{'Content-Length'} = length($content);
            }