From 8ea6ed3b82677001b35499850fb7516a99992b45 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Wed, 26 May 2021 18:43:19 -0400 Subject: [PATCH] Use localhost host header for loopback/domain sockets (Issue #185) --- CHANGES.md | 2 ++ cups/http.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 29faad9de3..5d99e6a3ca 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -42,6 +42,8 @@ CUPS v2.4rc1 (Pending) - Now use a 60 second timeout for reading USB backchannel data (Issue #160) - The USB backend now tries harder to find a serial number (Issue #170) - Fixed `@IF(name)` handling in `cupsd.conf` (Apple #5918) +- Now always pass "localhost" in the `Host:` header when talking over a domain + socket or the loopback interface (Issue #185) - Fixed a job history update issue in the scheduler (Issue #187) - Fixed `job-pages-per-set` value for duplex print jobs. - Documentation fixes (Issue #92, Issue #163, Issue #177, Issue #184) diff --git a/cups/http.c b/cups/http.c index f7331036d0..15881aed0b 100644 --- a/cups/http.c +++ b/cups/http.c @@ -4402,14 +4402,19 @@ http_send(http_t *http, /* I - HTTP connection */ } for (i = 0; i < HTTP_FIELD_MAX; i ++) + { if ((value = httpGetField(http, i)) != NULL && *value) { DEBUG_printf(("5http_send: %s: %s", http_fields[i], value)); if (i == HTTP_FIELD_HOST) { - if (httpPrintf(http, "Host: %s:%d\r\n", value, - httpAddrPort(http->hostaddr)) < 1) + // Issue #185: Use "localhost" for the loopback addresses to work + // around an Avahi bug... + if (httpAddrLocalhost(http->hostaddr)) + value = "localhost"; + + if (httpPrintf(http, "Host: %s:%d\r\n", value, httpAddrPort(http->hostaddr)) < 1) { http->status = HTTP_STATUS_ERROR; return (-1); @@ -4421,6 +4426,7 @@ http_send(http_t *http, /* I - HTTP connection */ return (-1); } } + } if (http->cookie) if (httpPrintf(http, "Cookie: $Version=0; %s\r\n", http->cookie) < 1) -- 2.47.2