From fe0f8c5263a45bf6a5ec53a0b744d735b0c6ee7a Mon Sep 17 00:00:00 2001
From: arnested <arnested@245635.no-reply.drupal.org>
Date: Sun, 9 Dec 2012 14:01:41 +0100
Subject: [PATCH] Add WWW-Authenticate header to unauthorized requests.
Reply-To: Arne =?UTF-8?Q?J=C3=B8rgensen?= <arne@arnested.dk>

---
 services_basic_auth.module | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/services_basic_auth.module b/services_basic_auth.module
index 8c67061..2363657 100644
--- a/services_basic_auth.module
+++ b/services_basic_auth.module
@@ -16,3 +16,19 @@ function services_basic_auth_services_authentication_info() {
     'authenticate_call' => '_services_basic_auth_authenticate_call',
   );
 }
+
+/**
+ * Implements hook_rest_server_execute_errors_alter().
+ *
+ * HTTP Basic Authentication must add a "WWW-Authenticate" header on
+ * unauthorized requests. Some clients (i.e. lynx) will not work properly
+ * without this.
+ *
+ * This hook was introduced in the services module version 3.3 and will have no
+ * effect on versions prior to this.
+ */
+function services_basic_auth_rest_server_execute_errors_alter(&$error, $controller, $arguments) {
+  if ($error['code'] == 401) {
+    drupal_add_http_header('WWW-Authenticate', 'Basic realm="' . check_plain(variable_get('site_name'), 'Drupal') . '"');
+  }
+}
-- 
1.8.0.1

