From eb9e22e5e652781b009ce6242cfb6d86711193f6 Mon Sep 17 00:00:00 2001
From: arnested <arnested@245635.no-reply.drupal.org>
Date: Wed, 5 Dec 2012 09:56:23 +0100
Subject: [PATCH] Add WWW-Authenticate header to unauthorized requests.

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

diff --git a/services_basic_auth.inc b/services_basic_auth.inc
index c843bd6..42eed5d 100644
--- a/services_basic_auth.inc
+++ b/services_basic_auth.inc
@@ -34,3 +34,19 @@ function _services_basic_auth_authenticate_call($settings, $method, $args) {
     }
   }
 }
+
+/**
+ * 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

