Index: includes/bootstrap.inc
--- includes/bootstrap.inc.orig	2008-02-11 15:36:21 +0100
+++ includes/bootstrap.inc	2008-04-09 20:47:49 +0200
@@ -730,6 +730,7 @@
  */
 function drupal_settings_initialize() {
   global $base_url, $base_path, $base_root;
+  global $base_url_local;
 
   // Export the following settings.php variables to the global namespace
   global $databases, $cookie_domain, $conf, $installed_profile, $update_free_access, $db_url, $db_prefix, $drupal_hash_salt, $is_https, $base_secure_url, $base_insecure_url;
@@ -1613,8 +1614,22 @@
  * equivalent using other environment variables.
  */
 function request_uri() {
+  global $base_url;
+  global $base_url_local;
+
   if (isset($_SERVER['REQUEST_URI'])) {
     $uri = $_SERVER['REQUEST_URI'];
+    if (isset($base_url) && isset($base_url_local)) {
+      $parts = parse_url($base_url_local);
+      if (   strlen($uri) >= strlen($base_url_local)
+          && substr($uri, 0, strlen($base_url_local)) == $base_url_local) {
+        $uri = $base_url .  substr($uri, strlen($base_url_local));
+      }
+      elseif (   strlen($uri) >= strlen($parts["path"])
+          && substr($uri, 0, strlen($parts["path"])) == $parts["path"]) {
+        $uri = $base_url .  substr($uri, strlen($parts["path"]));
+      }
+    }
   }
   else {
     if (isset($_SERVER['argv'])) {
@@ -1628,6 +1643,7 @@
     }
   }
   // Prevent multiple slashes to avoid cross site requests via the Form API.
+  if (substr($uri, 0, 1) == "/")
   $uri = '/' . ltrim($uri, '/');
 
   return $uri;
Index: includes/common.inc
--- includes/common.inc.orig	2008-04-09 23:11:44 +0200
+++ includes/common.inc	2008-06-26 20:16:16 +0200
@@ -848,9 +848,14 @@
   }
 
   // Construct the path to act on.
-  $path = isset($uri['path']) ? $uri['path'] : '/';
-  if (isset($uri['query'])) {
-    $path .= '?' . $uri['query'];
+  if (variable_get('proxy_server', '') != '') {
+    $path = $url;
+  }
+  else {
+    $path = isset($uri['path']) ? $uri['path'] : '/';
+    if (isset($uri['query'])) {
+      $path .= '?'. $uri['query'];
+    }
   }
 
   // Merge the default headers.
@@ -872,6 +877,14 @@
     $options['headers']['Authorization'] = 'Basic ' . base64_encode($uri['user'] . (isset($uri['pass']) ? ':' . $uri['pass'] : ''));
   }
 
+  // If the proxy server required a username then attempt to authenticate with it
+  if (variable_get('proxy_username', '') != '') {
+    $username = variable_get('proxy_username', '');
+    $password = variable_get('proxy_password', '');
+    $auth_string = base64_encode($username . ($password != '' ? ':'. $password : ''));
+    $defaults['Proxy-Authorization'] = 'Proxy-Authorization: Basic '. $auth_string ."\r\n";
+  }
+
   // If the database prefix is being used by SimpleTest to run the tests in a copied
   // database then set the user-agent header to the database prefix so that any
   // calls to other Drupal pages will run the SimpleTest prefixed database. The
Index: modules/system/system.admin.inc
--- modules/system/system.admin.inc.orig	2012-10-17 22:45:04.000000000 +0200
+++ modules/system/system.admin.inc	2012-10-27 13:56:02.343450754 +0200
@@ -1766,6 +1766,65 @@
 }
 
 /**
+ * Form builder; Configure the site proxy settings.
+ *
+ * @ingroup forms
+ * @see system_settings_form()
+ */
+function system_proxy_settings() {
+
+  $form['forward_proxy'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Forward proxy settings'),
+    '#description' => t('The proxy server used when Drupal needs to connect to other sites on the Internet.'),
+  );
+  $form['forward_proxy']['proxy_server'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Proxy host name'),
+    '#default_value' => variable_get('proxy_server', ''),
+    '#description' => t('The host name of the proxy server, eg. localhost. If this is empty Drupal will connect directly to the internet.')
+  );
+  $form['forward_proxy']['proxy_port'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Proxy port number'),
+    '#default_value' => variable_get('proxy_port', 8080),
+    '#description' => t('The port number of the proxy server, eg. 8080'),
+  );
+  $form['forward_proxy']['proxy_username'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Proxy username'),
+    '#default_value' => variable_get('proxy_username', ''),
+    '#description' => t('The username used to authenticate with the proxy server.'),
+  );
+  $form['forward_proxy']['proxy_password'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Proxy password'),
+    '#default_value' => variable_get('proxy_password', ''),
+    '#description' => t('The password used to connect to the proxy server. This is kept as plain text.', '')
+  );
+  $form['#validate'][] = 'system_proxy_settings_validate';
+
+  return system_settings_form($form);
+}
+
+/**
+ * Validate the submitted proxy form.
+ */
+function system_proxy_settings_validate($form, &$form_state) {
+  // Validate the proxy settings
+  $form_state['values']['proxy_server'] = trim($form_state['values']['proxy_server']);
+  if ($form_state['values']['proxy_server'] != '') {
+    // TCP allows the port to be between 0 and 65536 inclusive
+    if (!is_numeric($form_state['values']['proxy_port'])) {
+      form_set_error('proxy_port', t('The proxy port is invalid. It must be a number between 0 and 65535.'));
+    }
+    elseif ($form_state['values']['proxy_port'] < 0 || $form_state['values']['proxy_port'] >= 65536) {
+      form_set_error('proxy_port', t('The proxy port is invalid. It must be between 0 and 65535.'));
+    }
+  }
+}
+
+/**
  * Form builder; Configure the site file handling.
  *
  * @ingroup forms
Index: modules/system/system.module
--- modules/system/system.module.orig	2008-04-09 23:11:49 +0200
+++ modules/system/system.module	2008-04-24 11:43:47 +0200
@@ -723,6 +723,14 @@
     'access arguments' => array('access administration pages'),
     'file' => 'system.admin.inc',
   );
+  $items['admin/settings/proxy'] = array(
+    'title' => 'Proxy server',
+    'description' => 'Configure settings when the site is behind a proxy server.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('system_proxy_settings'),
+    'access arguments' => array('administer site configuration'),
+    'file' => 'system.admin.inc',
+  );
   $items['admin/config/media/file-system'] = array(
     'title' => 'File system',
     'description' => 'Tell Drupal where to store uploaded files and how they are accessed.',
Index: includes/install.core.inc
--- includes/install.core.inc.orig	2012-08-01 18:27:42.000000000 +0200
+++ includes/install.core.inc	2012-08-22 21:55:27.582420660 +0200
@@ -1770,7 +1770,7 @@
       1 => st('Check for updates automatically'),
       2 => st('Receive e-mail notifications'),
     ),
-    '#default_value' => array(1, 2),
+    '#default_value' => array(),
     '#description' => st('The system will notify you when updates and important security releases are available for installed components. Anonymous information about your site is sent to <a href="@drupal">Drupal.org</a>.', array('@drupal' => 'http://drupal.org')),
     '#weight' => 15,
   );
Index: sites/default/default.settings.php
--- sites/default/default.settings.php.orig	2012-08-01 18:27:42.000000000 +0200
+++ sites/default/default.settings.php	2012-08-22 21:39:06.793031214 +0200
@@ -257,6 +257,24 @@
 # $base_url = 'http://www.example.com';  // NO trailing slash!
 
 /**
+ * Local Base URL (optional).
+ *
+ * If you are running Drupal behind a reverse proxy, $base_url (see above)
+ * usually points to the URL of the reverse proxy. Drupal uses this for
+ * all sorts of external URLs. In order to correctly calculate sub-URLs
+ * below $base_url for embedded HTML forms, Drupal also has to know the
+ * URL on the local/origin server under which Drupal is contacted by the
+ * reverse proxy. This is what $base_url_local is for.
+ *
+ * Examples:
+ *   $base_url_local = 'http://www.example.com:8080/drupal';
+ *
+ * It is not allowed to have a trailing slash; Drupal will add it
+ * for you.
+ */
+# $base_url_local = 'http://www.example.com:8080/drupal';  // NO trailing slash!
+
+/**
  * PHP settings:
  *
  * To see what PHP settings are possible, including whether they can be set at
