Skip to content

Commit 219a47d

Browse files
author
Yang Lyu
committed
resolve the ETag issue when restarting BrowserLink.
1 parent b6abc14 commit 219a47d

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Threading.Tasks;
66
using Microsoft.AspNetCore.Http;
7+
using Microsoft.AspNetCore.Http.Headers;
78

89
namespace Microsoft.VisualStudio.Web.BrowserLink
910
{
@@ -23,8 +24,6 @@ internal class BrowserLinkMiddleware
2324
private RequestDelegate _next;
2425
private string _applicationPath;
2526

26-
private const string headerIfNoneMatch = "If-None-Match";
27-
2827
internal BrowserLinkMiddleware(string applicationPath, RequestDelegate next)
2928
{
3029
_applicationPath = applicationPath;
@@ -46,7 +45,9 @@ internal Task Invoke(HttpContext context)
4645
}
4746
else
4847
{
49-
if (context.Request.Headers.ContainsKey(headerIfNoneMatch) && BrowserLinkMiddleWareUtil.GetRequestPort(context.Request.Headers) != -1)
48+
RequestHeaders requestHeader = new RequestHeaders(context.Request.Headers);
49+
50+
if (requestHeader.IfNoneMatch != null && BrowserLinkMiddleWareUtil.GetRequestPort(context.Request.Headers) != -1)
5051
{
5152
BrowserLinkMiddleWareUtil.RemoveETagAndTimeStamp(context.Request.Headers);
5253
}
@@ -226,7 +227,9 @@ private static bool EnsureHostServerStarted(string applicationPath, ref HostConn
226227

227228
private void PreprocessRequestHeader(HttpContext httpContext, ref int currentPort)
228229
{
229-
if (httpContext.Request.Headers.ContainsKey(headerIfNoneMatch))
230+
RequestHeaders requestHeader = new RequestHeaders(httpContext.Request.Headers);
231+
232+
if (requestHeader.IfNoneMatch != null)
230233
{
231234
HostConnectionData connectionData;
232235

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
using System;
33
using Microsoft.AspNetCore.Http.Headers;
44
using Microsoft.Net.Http.Headers;
5-
using Microsoft.Extensions.Primitives;
5+
using System.Collections.Generic;
66

77
namespace Microsoft.VisualStudio.Web.BrowserLink
88
{
99
internal static class BrowserLinkMiddleWareUtil
1010
{
11-
private const string headerIfNoneMatch = "If-None-Match";
12-
1311
internal static int GetRequestPort(IHeaderDictionary headers)
1412
{
1513
RequestHeaders requestHeader = new RequestHeaders(headers);
@@ -52,23 +50,24 @@ internal static void RemoveETagAndTimeStamp(IHeaderDictionary headers)
5250
internal static void DeletePortFromETag(IHeaderDictionary headers)
5351
{
5452
RequestHeaders requestHeader = new RequestHeaders(headers);
55-
string newEtag = "";
53+
string newETag = "";
54+
IList<EntityTagHeaderValue> list = requestHeader.IfNoneMatch;
5655

57-
foreach(EntityTagHeaderValue value in requestHeader.IfNoneMatch)
56+
foreach(EntityTagHeaderValue value in list)
5857
{
5958
String[] strings = value.ToString().Split(':');
6059

6160
if (strings.Length >= 2)
6261
{
63-
newEtag = strings[0] + "\"";
62+
newETag = strings[0] + "\"";
6463
break;
6564
}
6665
}
6766

68-
if (newEtag.Length > 0)
67+
if (newETag.Length > 0)
6968
{
70-
headers.Remove(headerIfNoneMatch);
71-
headers.Add(headerIfNoneMatch, new StringValues(newEtag));
69+
list[0] = new EntityTagHeaderValue(newETag);
70+
requestHeader.IfNoneMatch = list;
7271
}
7372
}
7473

0 commit comments

Comments
 (0)