Skip to content

Commit 533ddac

Browse files
author
Yang Lyu
committed
Resolve some previous issues
1 parent 63adac8 commit 533ddac

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ internal class BrowserLinkMiddleware
2525
private RequestDelegate _next;
2626
private string _applicationPath;
2727

28-
private static string _hostUrl;
29-
3028
internal BrowserLinkMiddleware(string applicationPath, RequestDelegate next)
3129
{
3230
_applicationPath = applicationPath;
@@ -39,20 +37,18 @@ internal BrowserLinkMiddleware(string applicationPath, RequestDelegate next)
3937
internal Task Invoke(HttpContext context)
4038
{
4139
string requestId = Guid.NewGuid().ToString("N");
42-
43-
IHttpSocketAdapter injectScriptSocket = GetSocketConnectionToHost(_applicationPath, requestId, "injectScriptLink", context.Request.IsHttps);
4440
RequestHeaders requestHeader = new RequestHeaders(context.Request.Headers);
4541

46-
_hostUrl = BrowserLinkMiddleWareUtil.GetRequestUrl(requestHeader);
47-
42+
string hostUrl = BrowserLinkMiddleWareUtil.GetRequestUrl(requestHeader);
43+
44+
IHttpSocketAdapter injectScriptSocket = GetSocketConnectionToHost(_applicationPath, requestId, "injectScriptLink", context.Request.IsHttps, hostUrl);
45+
4846
if (injectScriptSocket != null)
4947
{
5048
return ExecuteWithFilter(injectScriptSocket, requestId, context);
5149
}
5250
else
5351
{
54-
// RequestHeaders requestHeader = new RequestHeaders(context.Request.Headers);
55-
5652
if (requestHeader.IfNoneMatch != null && BrowserLinkMiddleWareUtil.GetRequestPort(requestHeader).Count != 0)
5753
{
5854
BrowserLinkMiddleWareUtil.RemoveETagAndTimeStamp(requestHeader);
@@ -64,7 +60,11 @@ internal Task Invoke(HttpContext context)
6460

6561
private PageExecutionListenerFeature AddPageExecutionListenerFeatureTo(HttpContext context, string requestId)
6662
{
67-
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);
6868

6969
if (mappingDataSocket != null)
7070
{
@@ -131,7 +131,7 @@ private Task ExecuteWithoutFilter(HttpContext context)
131131
return _next(context);
132132
}
133133

134-
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)
135135
{
136136
// The host should send an initial response immediately after
137137
// the connection is established. If it fails to do so multiple times,
@@ -153,7 +153,7 @@ private static IHttpSocketAdapter GetSocketConnectionToHost(string applicationPa
153153
{
154154
IHttpSocketAdapter httpSocket = await HttpSocketAdapter.OpenHttpSocketAsync("GET", new Uri(connectionString, rpcMethod));
155155

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

158158
return httpSocket;
159159
}
@@ -165,7 +165,7 @@ private static IHttpSocketAdapter GetSocketConnectionToHost(string applicationPa
165165
return null;
166166
}
167167

168-
private static void AddRequestHeaders(IHttpSocketAdapter httpSocket, string requestId, bool isHttps)
168+
private static void AddRequestHeaders(IHttpSocketAdapter httpSocket, string requestId, bool isHttps, string hostUrl)
169169
{
170170
httpSocket.AddRequestHeader(BrowserLinkConstants.RequestIdHeaderName, requestId);
171171

@@ -178,8 +178,7 @@ private static void AddRequestHeaders(IHttpSocketAdapter httpSocket, string requ
178178
httpSocket.AddRequestHeader(BrowserLinkConstants.RequestScheme, "http");
179179
}
180180

181-
httpSocket.AddRequestHeader(BrowserLinkConstants.RequestTest, "testValue");
182-
httpSocket.AddRequestHeader(BrowserLinkConstants.RequestHostUrl, _hostUrl);
181+
httpSocket.AddRequestHeader(BrowserLinkConstants.RequestHostUrl, hostUrl);
183182
}
184183

185184
private static bool FindAndSignalHostConnection(string applicationPath)

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

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

51-
public const string RequestTest = "TestKey";
52-
51+
/// <summary>
52+
/// The url of the host used for project match.
53+
/// </summary>
5354
public const string RequestHostUrl = "HostUrl";
5455

5556
/// <summary>

0 commit comments

Comments
 (0)