public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH http-server v2 1/2] add error message into http body
@ 2025-01-28 14:41 Dominik Csapak
  2025-01-28 14:41 ` [pve-devel] [PATCH http-server v2 2/2] use HTTP_INTERNAL_SERVER_ERROR were appropriate instead of '501' Dominik Csapak
  2025-01-28 14:52 ` [pve-devel] applied-series: [PATCH http-server v2 1/2] add error message into http body Thomas Lamprecht
  0 siblings, 2 replies; 3+ messages in thread
From: Dominik Csapak @ 2025-01-28 14:41 UTC (permalink / raw)
  To: pve-devel

In our rust client, we can't access the http reason phrases[0], so let's
put them into the body itself if we don't specify an explicit content.

our proxmox-client code in rust already uses the body as message if
there is one [1], so we get that automatically.

0: https://github.com/hyperium/http/issues/737
1: https://git.proxmox.com/?p=proxmox.git;a=blob;f=proxmox-client/src/client.rs;h=9b078a9820405b22ca54c17ea4da4c586e0649b4;hb=refs/heads/master#l237

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from rfc:
* add a comment why we don't set the content type

 src/PVE/APIServer/AnyEvent.pm | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm
index b94e1aa..9a1e35a 100644
--- a/src/PVE/APIServer/AnyEvent.pm
+++ b/src/PVE/APIServer/AnyEvent.pm
@@ -389,6 +389,9 @@ sub error {
     my ($self, $reqstate, $code, $msg, $hdr, $content) = @_;
 
     eval {
+	$content //= $msg; # write error into body by default
+	# lack of content type here means either 'application/octet-stream' or the client
+	# can guess. This is fine since we don't know what content/msg actually contains.
 	my $resp = HTTP::Response->new($code, $msg, $hdr, $content);
 	$self->response($reqstate, $resp);
     };
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pve-devel] [PATCH http-server v2 2/2] use HTTP_INTERNAL_SERVER_ERROR were appropriate instead of '501'
  2025-01-28 14:41 [pve-devel] [PATCH http-server v2 1/2] add error message into http body Dominik Csapak
@ 2025-01-28 14:41 ` Dominik Csapak
  2025-01-28 14:52 ` [pve-devel] applied-series: [PATCH http-server v2 1/2] add error message into http body Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Dominik Csapak @ 2025-01-28 14:41 UTC (permalink / raw)
  To: pve-devel

The http status code 501 is meant to be 'Not Implemented'[0] but that
clearly does not fit here as the default error when we encounter a
problem during handling an api request or upload.

So instead use '500' (HTTP_INTERNAL_SERVER_ERROR) which we already use
in other places where it fits.

0: https://datatracker.ietf.org/doc/html/rfc9110#name-501-not-implemented

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from rfc:
* only change the code where it actually make sense, the other instances
  were cases of us not implementing part of the request so 501 there
  was ok in the first place

 src/PVE/APIServer/AnyEvent.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm
index 9a1e35a..469dd28 100644
--- a/src/PVE/APIServer/AnyEvent.pm
+++ b/src/PVE/APIServer/AnyEvent.pm
@@ -507,7 +507,7 @@ sub send_file_start {
 	    $self->response($reqstate, $resp, $mtime, $nocomp);
 	};
 	if (my $err = $@) {
-	    $self->error($reqstate, 501, $err);
+	    $self->error($reqstate, HTTP_INTERNAL_SERVER_ERROR, $err);
 	}
     };
 
@@ -1023,7 +1023,7 @@ sub handle_api2_request {
 	$self->response($reqstate, $resp, undef, $nocomp, $delay);
     };
     if (my $err = $@) {
-	$self->error($reqstate, 501, $err);
+	$self->error($reqstate, HTTP_INTERNAL_SERVER_ERROR, $err);
     }
 }
 
@@ -1217,7 +1217,7 @@ sub handle_request {
 	die "no such file '$path'\n";
     };
     if (my $err = $@) {
-	$self->error($reqstate, 501, $err);
+	$self->error($reqstate, HTTP_INTERNAL_SERVER_ERROR, $err);
     }
 }
 
@@ -1307,7 +1307,7 @@ sub file_upload_multipart {
     };
     if (my $err = $@) {
 	syslog('err', $err);
-	$self->error($reqstate, 501, $err);
+	$self->error($reqstate, HTTP_INTERNAL_SERVER_ERROR, $err);
     }
 }
 
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pve-devel] applied-series: [PATCH http-server v2 1/2] add error message into http body
  2025-01-28 14:41 [pve-devel] [PATCH http-server v2 1/2] add error message into http body Dominik Csapak
  2025-01-28 14:41 ` [pve-devel] [PATCH http-server v2 2/2] use HTTP_INTERNAL_SERVER_ERROR were appropriate instead of '501' Dominik Csapak
@ 2025-01-28 14:52 ` Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2025-01-28 14:52 UTC (permalink / raw)
  To: Proxmox VE development discussion, Dominik Csapak

Am 28.01.25 um 15:41 schrieb Dominik Csapak:
> In our rust client, we can't access the http reason phrases[0], so let's
> put them into the body itself if we don't specify an explicit content.
> 
> our proxmox-client code in rust already uses the body as message if
> there is one [1], so we get that automatically.
> 
> 0: https://github.com/hyperium/http/issues/737
> 1: https://git.proxmox.com/?p=proxmox.git;a=blob;f=proxmox-client/src/client.rs;h=9b078a9820405b22ca54c17ea4da4c586e0649b4;hb=refs/heads/master#l237
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> changes from rfc:
> * add a comment why we don't set the content type
> 
>  src/PVE/APIServer/AnyEvent.pm | 3 +++
>  1 file changed, 3 insertions(+)
> 
>

applied both patches, thanks!


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-28 14:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-28 14:41 [pve-devel] [PATCH http-server v2 1/2] add error message into http body Dominik Csapak
2025-01-28 14:41 ` [pve-devel] [PATCH http-server v2 2/2] use HTTP_INTERNAL_SERVER_ERROR were appropriate instead of '501' Dominik Csapak
2025-01-28 14:52 ` [pve-devel] applied-series: [PATCH http-server v2 1/2] add error message into http body Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal