Index: src/wp-includes/link-template.php
===================================================================
--- src/wp-includes/link-template.php	(revision 35925)
+++ src/wp-includes/link-template.php	(working copy)
@@ -3370,6 +3370,20 @@
 function set_url_scheme( $url, $scheme = null ) {
 	$orig_scheme = $scheme;
 
+	// if we're switched on multisite and no specific scheme is requested, try to detect it from the URL
+	if ( is_multisite() && ! empty( $GLOBALS['_wp_switched_stack'] ) ) {
+		if ( ! $scheme
+			|| ( 'admin' === $scheme || 'login' === $scheme || 'login_post' === $scheme || 'rpc' === $scheme ) && ! force_ssl_admin()
+			|| 'http' !== $scheme && 'https' !== $scheme && 'relative' !== $scheme
+		) {
+			if ( 0 === strpos( $url, 'https://' ) ) {
+				$scheme = 'https';
+			} elseif ( 0 === strpos( $url, 'http://' ) ) {
+				$scheme = 'http';
+			}
+		}
+	}
+
 	if ( ! $scheme ) {
 		$scheme = is_ssl() ? 'https' : 'http';
 	} elseif ( $scheme === 'admin' || $scheme === 'login' || $scheme === 'login_post' || $scheme === 'rpc' ) {
