]> git.proxmox.com Git - pve-http-server.git/blobdiff - PVE/APIServer/AnyEvent.pm
followup: adapt coding style to surrounding
[pve-http-server.git] / PVE / APIServer / AnyEvent.pm
index eac788bc25dc36ae6d3e11fb36418a0e14efd80a..468edb441ebebab0ed742b78c6733917857e3167 100755 (executable)
@@ -184,6 +184,7 @@ sub response {
     $reqstate->{hdl}->timeout_reset();
     $reqstate->{hdl}->timeout($self->{timeout});
 
+    $nocomp = 1 if !$self->{compression};
     $nocomp = 1 if !$reqstate->{accept_gzip};
 
     my $code = $resp->code;
@@ -345,7 +346,7 @@ sub websocket_proxy {
        my $remhost;
        my $remport;
 
-       my $max_payload_size = 65536;
+       my $max_payload_size = 128*1024;
 
        my $binary;
        if ($wsproto eq 'binary') {
@@ -374,8 +375,8 @@ sub websocket_proxy {
 
            $reqstate->{proxyhdl} = AnyEvent::Handle->new(
                fh => $fh,
-               rbuf_max => 64*1024,
-               wbuf_max => 64*10*1024,
+               rbuf_max => $max_payload_size,
+               wbuf_max => $max_payload_size*5,
                timeout => 5,
                on_eof => sub {
                    my ($hdl) = @_;
@@ -398,7 +399,7 @@ sub websocket_proxy {
                my ($hdl) = @_;
 
                my $len = length($hdl->{rbuf});
-               my $data = substr($hdl->{rbuf}, 0, $len, '');
+               my $data = substr($hdl->{rbuf}, 0, $len > $max_payload_size ? $max_payload_size : $len, '');
 
                my $string;
                my $payload;
@@ -552,7 +553,7 @@ sub proxy_request {
 
        $headers->{'cookie'} = PVE::APIServer::Formatter::create_auth_cookie($ticket, $self->{cookie_name}) if $ticket;
        $headers->{'CSRFPreventionToken'} = $token if $token;
-       $headers->{'Accept-Encoding'} = 'gzip' if $reqstate->{accept_gzip};
+       $headers->{'Accept-Encoding'} = 'gzip' if ($reqstate->{accept_gzip} && $self->{compression});
 
        my $content;
 
@@ -867,7 +868,8 @@ sub handle_spice_proxy_request {
 
                # todo: use stop_read/start_read if write buffer grows to much
 
-               my $res = "$proto 200 OK\015\012"; # hope this is the right answer?
+               # a response must be followed by an empty line
+               my $res = "$proto 200 OK\015\012\015\012";
                $reqstate->{hdl}->push_write($res);
 
                # log early
@@ -889,7 +891,10 @@ sub handle_spice_proxy_request {
                    my ($hdl, $line) = @_;
 
                    if ($line =~ m!^$proto 200 OK$!) {
-                       &$startproxy();
+                       # read the empty line after the 200 OK
+                       $reqstate->{proxyhdl}->unshift_read(line => sub{
+                           &$startproxy();
+                       });
                    } else {
                        $reqstate->{hdl}->push_write($line);
                        $self->client_do_disconnect($reqstate);
@@ -1607,6 +1612,7 @@ sub new {
     $self->{base_uri} //= "/api2";
     $self->{dirs} //= {};
     $self->{title} //= 'API Inspector';
+    $self->{compression} //= 1;
 
     # formatter_config: we pass some configuration values to the Formatter
     $self->{formatter_config} = {};
@@ -1640,8 +1646,13 @@ sub new {
     $self->{end_cond} = AnyEvent->condvar;
 
     if ($self->{ssl}) {
+       my $tls_ctx_flags = &Net::SSLeay::OP_NO_COMPRESSION | &Net::SSLeay::OP_SINGLE_ECDH_USE | &Net::SSLeay::OP_SINGLE_DH_USE;
+       if ( delete $self->{ssl}->{honor_cipher_order} ) {
+           $tls_ctx_flags |= &Net::SSLeay::OP_CIPHER_SERVER_PREFERENCE;
+       }
+
        $self->{tls_ctx} = AnyEvent::TLS->new(%{$self->{ssl}});
-       Net::SSLeay::CTX_set_options($self->{tls_ctx}->{ctx}, &Net::SSLeay::OP_NO_COMPRESSION | &Net::SSLeay::OP_SINGLE_ECDH_USE | &Net::SSLeay::OP_SINGLE_DH_USE);
+       Net::SSLeay::CTX_set_options($self->{tls_ctx}->{ctx}, $tls_ctx_flags);
     }
 
     if ($self->{spiceproxy}) {