commit 9182d077f2c2271363ffcd9b51d43ad48fba69d0
parent c8be73d92ed5f6e439a9b51209ac33b8f519dfec
Author: David Goulet <dgoulet@torproject.org>
Date: Thu, 20 Nov 2025 16:03:56 +0000
Merge branch 'http_connect_end_reason' into 'main'
http-connect: Report end reasons and errors per the spec.
See merge request tpo/core/tor!955
Diffstat:
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c
@@ -3942,6 +3942,17 @@ connection_ap_handshake_socks_reply(entry_connection_t *conn, char *reply,
connection_buf_add(HTTP_CONNECT_FIXED_HEADERS,
strlen(HTTP_CONNECT_FIXED_HEADERS),
ENTRY_TO_CONN(conn));
+ if (endreason) {
+ bool reason_is_remote = (endreason & END_STREAM_REASON_MASK) < 256;
+ const char *reason = stream_end_reason_to_control_string(endreason);
+ if (reason) {
+ const char *prefix = reason_is_remote ? "end" : "c-tor";
+ tor_snprintf(buf, sizeof(buf),
+ "Tor-Request-Failed: %s/%s\r\n",
+ prefix, reason);
+ connection_buf_add(buf, strlen(buf), ENTRY_TO_CONN(conn));
+ }
+ }
connection_buf_add("\r\n", 2, ENTRY_TO_CONN(conn));
} else if (conn->socks_request->socks_version == 4) {
memset(buf,0,SOCKS4_NETWORK_LEN);
diff --git a/src/core/or/reasons.c b/src/core/or/reasons.c
@@ -23,7 +23,11 @@
/***************************** Edge (stream) reasons **********************/
/** Convert the reason for ending a stream <b>reason</b> into the format used
- * in STREAM events. Return NULL if the reason is unrecognized. */
+ * in STREAM events. Return NULL if the reason is unrecognized.
+ *
+ * Note: For all specified remote reasons that can occur in a Relay END
+ * message, these are the same as the specified name of the END reason.
+ */
const char *
stream_end_reason_to_control_string(int reason)
{