-
Notifications
You must be signed in to change notification settings - Fork 23
Dev/billhie/get browser link building #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
BillHiebert
wants to merge
3
commits into
aspnet:main
Choose a base branch
from
BillHiebert:dev/billhie/GetBrowserLinkBuilding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/Microsoft.VisualStudio.Web.BrowserLink/HostingStartup.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
||
[assembly: HostingStartup(typeof(Microsoft.VisualStudio.Web.BrowserLink.HostingStartup))] | ||
|
||
namespace Microsoft.VisualStudio.Web.BrowserLink | ||
{ | ||
internal sealed class HostingStartup : IHostingStartup, IStartupFilter | ||
{ | ||
public void Configure(IWebHostBuilder builder) | ||
{ | ||
builder.ConfigureServices(services => services.TryAddEnumerable(ServiceDescriptor.Singleton<IStartupFilter>(this))); | ||
} | ||
|
||
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next) | ||
{ | ||
return app => | ||
{ | ||
app.UseBrowserLink(); | ||
next(app); | ||
}; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 27 additions & 6 deletions
33
src/Microsoft.VisualStudio.Web.BrowserLink/SendFilesWrapper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,59 @@ | ||
using System.IO; | ||
using System.IO.Pipelines; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Http.Features; | ||
|
||
|
||
namespace Microsoft.VisualStudio.Web.BrowserLink | ||
{ | ||
internal class SendFilesWrapper : IHttpSendFileFeature | ||
internal class SendFilesWrapper : IHttpResponseBodyFeature | ||
{ | ||
private HttpResponse _response; | ||
private IHttpSendFileFeature _wrapped; | ||
private IHttpResponseBodyFeature _wrapped; | ||
|
||
internal SendFilesWrapper(IHttpSendFileFeature wrapped, HttpResponse response) | ||
internal SendFilesWrapper(IHttpResponseBodyFeature wrapped, HttpResponse response) | ||
{ | ||
_wrapped = wrapped; | ||
_response = response; | ||
} | ||
|
||
async Task IHttpSendFileFeature.SendFileAsync(string path, long offset, long? count, CancellationToken cancellation) | ||
public Stream Stream => _wrapped.Stream; | ||
|
||
public PipeWriter Writer => _wrapped.Writer; | ||
|
||
public Task CompleteAsync() | ||
{ | ||
return _wrapped.CompleteAsync(); | ||
} | ||
|
||
public void DisableBuffering() | ||
{ | ||
_wrapped.DisableBuffering(); | ||
} | ||
|
||
public async Task SendFileAsync(string path, long offset, long? count, CancellationToken cancellationToken = default) | ||
{ | ||
// TODO: Send mapping data to VS | ||
|
||
if (_wrapped != null) | ||
{ | ||
await _wrapped.SendFileAsync(path, offset, count, cancellation); | ||
await _wrapped.SendFileAsync(path, offset, count, cancellationToken); | ||
return; | ||
} | ||
|
||
using (Stream readStream = File.OpenRead(path)) | ||
{ | ||
readStream.Seek(offset, SeekOrigin.Begin); | ||
|
||
await readStream.CopyToAsync(_response.Body, 4096, cancellation); | ||
await readStream.CopyToAsync(_response.Body, 4096, cancellationToken); | ||
} | ||
} | ||
|
||
public Task StartAsync(CancellationToken cancellationToken = default) | ||
{ | ||
return _wrapped.StartAsync(cancellationToken); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
internal class StartupHook | ||
{ | ||
public static void Initialize() | ||
{ | ||
// This method exists to make startup hook load successfully. We do not need to do anything interesting here. | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...soft.VisualStudio.Web.BrowserLink.Test/Microsoft.VisualStudio.Web.BrowserLink.Test.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks> | ||
<!--<TargetFrameworks>$(StandardTestTfms)</TargetFrameworks>--> | ||
|
||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Microsoft.VisualStudio.Web.BrowserLink\Microsoft.VisualStudio.Web.BrowserLink.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="$(MicrosoftAspNetCoreHttpPackageVersion)" /> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(MicrosoftAspNetCoreTestingPackageVersion)" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkPackageVersion)" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitRunnerVisualstudioPackageVersion)" /> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It used to be possible for _wrapped to be null, if app.UseStaticFiles() wasn't included. We should check all references for null to be on the safe side, so we don't cause runtime errors in working applications.