Skip to content

Commit df96d17

Browse files
author
Yang Lyu
authored
Merge pull request #34 from aspnet/yalyu/MappingContinue
Url match used for Dot Net Core project connection
2 parents 4d36395 + 533ddac commit df96d17

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

src/Microsoft.VisualStudio.Web.BrowserLink/BrowserLinkMiddleWare.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,18 @@ internal BrowserLinkMiddleware(string applicationPath, RequestDelegate next)
3737
internal Task Invoke(HttpContext context)
3838
{
3939
string requestId = Guid.NewGuid().ToString("N");
40+
RequestHeaders requestHeader = new RequestHeaders(context.Request.Headers);
4041

41-
IHttpSocketAdapter injectScriptSocket = GetSocketConnectionToHost(_applicationPath, requestId, "injectScriptLink", context.Request.IsHttps);
42+
string hostUrl = BrowserLinkMiddleWareUtil.GetRequestUrl(requestHeader);
4243

44+
IHttpSocketAdapter injectScriptSocket = GetSocketConnectionToHost(_applicationPath, requestId, "injectScriptLink", context.Request.IsHttps, hostUrl);
45+
4346
if (injectScriptSocket != null)
4447
{
4548
return ExecuteWithFilter(injectScriptSocket, requestId, context);
4649
}
4750
else
4851
{
49-
RequestHeaders requestHeader = new RequestHeaders(context.Request.Headers);
50-
5152
if (requestHeader.IfNoneMatch != null && BrowserLinkMiddleWareUtil.GetRequestPort(requestHeader).Count != 0)
5253
{
5354
BrowserLinkMiddleWareUtil.RemoveETagAndTimeStamp(requestHeader);
@@ -59,7 +60,11 @@ internal Task Invoke(HttpContext context)
5960

6061
private PageExecutionListenerFeature AddPageExecutionListenerFeatureTo(HttpContext context, string requestId)
6162
{
62-
IHttpSocketAdapter mappingDataSocket = GetSocketConnectionToHost(_applicationPath, requestId, "sendMappingData", context.Request.IsHttps);
63+
RequestHeaders requestHeader = new RequestHeaders(context.Request.Headers);
64+
65+
string hostUrl = BrowserLinkMiddleWareUtil.GetRequestUrl(requestHeader);
66+
67+
IHttpSocketAdapter mappingDataSocket = GetSocketConnectionToHost(_applicationPath, requestId, "sendMappingData", context.Request.IsHttps, hostUrl);
6368

6469
if (mappingDataSocket != null)
6570
{
@@ -126,7 +131,7 @@ private Task ExecuteWithoutFilter(HttpContext context)
126131
return _next(context);
127132
}
128133

129-
private static IHttpSocketAdapter GetSocketConnectionToHost(string applicationPath, string requestId, string rpcMethod, bool isHttps)
134+
private static IHttpSocketAdapter GetSocketConnectionToHost(string applicationPath, string requestId, string rpcMethod, bool isHttps, string hostUrl)
130135
{
131136
// The host should send an initial response immediately after
132137
// the connection is established. If it fails to do so multiple times,
@@ -148,7 +153,7 @@ private static IHttpSocketAdapter GetSocketConnectionToHost(string applicationPa
148153
{
149154
IHttpSocketAdapter httpSocket = await HttpSocketAdapter.OpenHttpSocketAsync("GET", new Uri(connectionString, rpcMethod));
150155

151-
AddRequestHeaders(httpSocket, requestId, isHttps);
156+
AddRequestHeaders(httpSocket, requestId, isHttps, hostUrl);
152157

153158
return httpSocket;
154159
}
@@ -160,7 +165,7 @@ private static IHttpSocketAdapter GetSocketConnectionToHost(string applicationPa
160165
return null;
161166
}
162167

163-
private static void AddRequestHeaders(IHttpSocketAdapter httpSocket, string requestId, bool isHttps)
168+
private static void AddRequestHeaders(IHttpSocketAdapter httpSocket, string requestId, bool isHttps, string hostUrl)
164169
{
165170
httpSocket.AddRequestHeader(BrowserLinkConstants.RequestIdHeaderName, requestId);
166171

@@ -172,6 +177,8 @@ private static void AddRequestHeaders(IHttpSocketAdapter httpSocket, string requ
172177
{
173178
httpSocket.AddRequestHeader(BrowserLinkConstants.RequestScheme, "http");
174179
}
180+
181+
httpSocket.AddRequestHeader(BrowserLinkConstants.RequestHostUrl, hostUrl);
175182
}
176183

177184
private static bool FindAndSignalHostConnection(string applicationPath)

src/Microsoft.VisualStudio.Web.BrowserLink/BrowserLinkMiddleWareUtil.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ internal static List<int> GetRequestPort(RequestHeaders requestHeader)
3232
return requestPortList;
3333
}
3434

35+
internal static string GetRequestUrl(RequestHeaders requstHeader)
36+
{
37+
return requstHeader.Host.ToString();
38+
}
39+
3540
internal static int GetCurrentPort(string connectionString)
3641
{
3742
Uri uri;

src/Microsoft.VisualStudio.Web.BrowserLink/Common/ArteryConstants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ internal static class BrowserLinkConstants
4848
/// </summary>
4949
public const string RequestScheme = "Scheme";
5050

51+
/// <summary>
52+
/// The url of the host used for project match.
53+
/// </summary>
54+
public const string RequestHostUrl = "HostUrl";
55+
5156
/// <summary>
5257
/// Suffix added to the end of the instance file name to identify a
5358
/// Version 2 instance file

0 commit comments

Comments
 (0)