public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: Thomas Lamprecht <t.lamprecht@proxmox.com>,
	Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Subject: Re: [pve-devel] [RFC PATCH http-server 1/2] add error message into http body
Date: Thu, 16 Jan 2025 08:31:59 +0100	[thread overview]
Message-ID: <f838efc6-fcbc-41b7-b391-8d5c49b32d9f@proxmox.com> (raw)
In-Reply-To: <7ffc1b0e-1d46-4f27-a0a9-f523b32d3108@proxmox.com>

On 1/15/25 17:08, Thomas Lamprecht wrote:
> Am 08.01.25 um 09:45 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>
>> ---
>>   src/PVE/APIServer/AnyEvent.pm | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm
>> index 24209a1..bd76488 100644
>> --- a/src/PVE/APIServer/AnyEvent.pm
>> +++ b/src/PVE/APIServer/AnyEvent.pm
>> @@ -388,6 +388,7 @@ sub error {
>>       my ($self, $reqstate, $code, $msg, $hdr, $content) = @_;
>>   
>>       eval {
>> +	$content //= $msg; # write error into body by default
> 
> might this need altering the content-type or is that already to an
> OK default for a plain string? Just not that it's set to, e.g.,
> application/json but contains the error that cannot be parsed
> as JSON.
> 
> I can look myself, but I thought you might have already done so when
> developing this.
> 
> If that's fine I'd have nothing against applying this now.

The newly created response here is not setting an explicit content-type, and
according to the relevant part of the http spec[0], the client may assume
'application/octet-stream' or may try to identify the content-type
from the content itself.

While I guess most of the time we put strings in the error, it may happen
that this is something different here (since we sometimes simply
pass through the message from 'die') so explicitly setting
to text/plain could also be sometimes wrong here.

So I'd either leave it like this, or reformat the message to be e.g.
always text in some form, e.g. with

if (!defined($content)) {
     $content = "Some error occured: $msg";
     # set content type here
}

0: https://www.rfc-editor.org/rfc/rfc9110.html#name-content-type

> 
>>   	my $resp = HTTP::Response->new($code, $msg, $hdr, $content);
>>   	$self->response($reqstate, $resp);
>>       };
> 



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


  reply	other threads:[~2025-01-16  7:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-08  8:45 [pve-devel] [RFC PATCH http-server 0/2] improve error handling on api errors Dominik Csapak
2025-01-08  8:45 ` [pve-devel] [RFC PATCH http-server 1/2] add error message into http body Dominik Csapak
2025-01-15 16:08   ` Thomas Lamprecht
2025-01-16  7:31     ` Dominik Csapak [this message]
2025-01-27 12:44       ` Dominik Csapak
2025-01-28 14:24         ` Thomas Lamprecht
2025-01-28 14:46           ` Dominik Csapak
2025-01-29 17:51             ` Thomas Lamprecht
2025-01-08  8:45 ` [pve-devel] [RFC PATCH http-server 2/2] use HTTP_INTERNAL_SERVER_ERROR were appropriate instead of '501' Dominik Csapak
2025-01-15 16:19   ` Thomas Lamprecht
2025-01-16  7:36     ` Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f838efc6-fcbc-41b7-b391-8d5c49b32d9f@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    --cc=t.lamprecht@proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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