Should bubble up HTTP error codes
My matrix server was unreachable for $reasons and libcmatrix did not handle the following type of response particularly graceful
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.22.1</center>
</body>
</html>
which the parser chokes on:
09:39:44.9331 cm-net[20810]: DEBUG: Error loading from stream: <data>:1:1: Parse error: unexpected character `<', expected value
[New Thread 0x7fffbb4006c0 (LWP 22400)]
09:39:44.9332 cm-user[20810]: DEBUG: (0x555556d365e0) Load info fail
09:39:44.9332 cm-net[20810]: DEBUG: Error loading from stream: <data>:1:1: Parse error: unexpected character `<', expected value
09:39:44.9333 cm-user[20810]: DEBUG: (0x555558d14620) Load info fail
[Thread 0x7fffbb4006c0 (LWP 22400) exited]
09:39:45.6686 cm-net[20810]: DEBUG: Error loading from stream: <data>:1:1: Parse error: unexpected character `<', expected value
09:39:45.6687 cm-user[20810]: DEBUG: (0x55555915c820) Load info fail
09:39:45.7218 cm-net[20810]: DEBUG: Error loading from stream: <data>:1:1: Parse error: unexpected character `<', expected value
09:39:45.7219 chatty-ma-chat[20810]: WARNING: Error updating read marker: <data>:1:1: Parse error: unexpected character `<', expected value
09:39:45.7684 cm-net[20810]: DEBUG: Error loading from stream: <data>:1:1: Parse error: unexpected character `<', expected value
The codepath hitting this goes something like
cm-net.c:session_send_cb()
- 'cm-net.c:read_from_stream()`
-
cm-net.c:parse_from_data()
where it fails to parse the above message
from soup_session_send*()
docs
On success, a GInputStream will be returned which you can use to read the response body. (“Success” here means only that an HTTP response was received and understood; it does not necessarily mean that a 2xx class status code was received.)
in order to get the status code we would need to either
-
keepit's already set as the tasks dataSoupMessage
around after sending, so that we cansoup_message_get_status()
on it or🎉 - use
headers_parse_(status_line|response)()
on theGInputStream
we receive fromsoup_session_send_finish()
, but this seems a bit clunky to me
Edited by Evangelos Ribeiro Tzaras