### Eclipse Workspace Patch 1.0
#P wordpress-trunk bare
Index: wp-includes/canonical.php
===================================================================
--- wp-includes/canonical.php	(revision 17523)
+++ wp-includes/canonical.php	(working copy)
@@ -42,9 +42,7 @@
 
 	if ( !$requested_url ) {
 		// build the URL in the address bar
-		$requested_url  = is_ssl() ? 'https://' : 'http://';
-		$requested_url .= $_SERVER['HTTP_HOST'];
-		$requested_url .= $_SERVER['REQUEST_URI'];
+		$requested_url = wp_requested_url();
 	}
 
 	$original = @parse_url($requested_url);
Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 17523)
+++ wp-includes/functions.php	(working copy)
@@ -3596,13 +3596,29 @@
 	if ( defined('WP_SITEURL') && '' != WP_SITEURL ) {
 		$url = WP_SITEURL;
 	} else {
-		$schema = is_ssl() ? 'https://' : 'http://';
-		$url = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
+		$url = wp_requested_url();
+		$url = preg_replace( '|/wp-admin/.*|i', '', $url );
 	}
 	return rtrim($url, '/');
 }
 
 /**
+ * Get the requested URL of the site
+ * 
+ * @since 3.2
+ * @param bool $ssl Optional. Override SSL property of the request, setting it to non-SSL or SSL explicitly
+ * @return string requested URL
+ */
+function wp_requested_url( $ssl = null ) {
+	$ssl = ( null === $ssl ) ? is_ssl() : $ssl;
+	$scheme = $ssl ? 'https' : 'http';
+	$default_port = $ssl ? '443' : '80';
+	list( $host, $port ) = explode( ':', $_SERVER['HTTP_HOST'] . ":$default_port" );
+	$host .= ( $port == $default_port ? '' : ":$port" );
+	return "$scheme://$host" . $_SERVER['REQUEST_URI'];
+}
+
+/**
  * Suspend cache invalidation.
  *
  * Turns cache invalidation on and off.  Useful during imports where you don't wont to do invalidations
Index: wp-admin/setup-config.php
===================================================================
--- wp-admin/setup-config.php	(revision 17523)
+++ wp-admin/setup-config.php	(working copy)
@@ -194,7 +194,7 @@
 		 * @ignore
 		 */
 		function get_bloginfo() {
-			return ( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . str_replace( $_SERVER['PHP_SELF'], '/wp-admin/setup-config.php', '' ) );
+			return str_replace( wp_requested_url(), '/wp-admin/setup-config.php', '' );
 		}
 		/**#@-*/
 		$secret_keys = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
Index: wp-login.php
===================================================================
--- wp-login.php	(revision 17523)
+++ wp-login.php	(working copy)
@@ -13,13 +13,8 @@
 
 // Redirect to https login if forced to use SSL
 if ( force_ssl_admin() && !is_ssl() ) {
-	if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
-		wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']));
-		exit();
-	} else {
-		wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
-		exit();
-	}
+	wp_redirect( wp_requested_url( true ) );
+	exit();
 }
 
 /**
@@ -357,9 +352,10 @@
 	if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
 		$_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
 
-	$schema = is_ssl() ? 'https://' : 'http://';
-	if ( dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_option('siteurl') )
-		update_option('siteurl', dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) );
+	$new_siteurl = dirname( wp_requested_url() );
+	if ( $new_siteurl != get_option('siteurl') )
+		update_option('siteurl', $new_siteurl );
+	unset($new_siteurl);
 }
 
 //Set a cookie now to see if they are supported by the browser.
Index: wp-admin/includes/class-wp-list-table.php
===================================================================
--- wp-admin/includes/class-wp-list-table.php	(revision 17523)
+++ wp-admin/includes/class-wp-list-table.php	(working copy)
@@ -475,7 +475,7 @@
 
 		$current = $this->get_pagenum();
 
-		$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+		$current_url = wp_requested_url();
 
 		$current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
 
@@ -631,7 +631,7 @@
 
 		list( $columns, $hidden, $sortable ) = $this->get_column_info();
 
-		$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+		$current_url = wp_requested_url();
 		$current_url = remove_query_arg( 'paged', $current_url );
 
 		if ( isset( $_GET['orderby'] ) )
