10000 Merge branch 'master' into accept-encoding-gzip · dotnet-script/dotnet-script@7911257 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7911257

Browse files
committed
Merge branch 'master' into accept-encoding-gzip
# Conflicts: # src/Dotnet.Script.Core/ScriptDownloader.cs
2 parents 3bdae3c + 75adbfd commit 7911257

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

build/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/dotnet/core/sdk:3.0
1+
FROM mcr.microsoft.com/dotnet/core/sdk:3.1
22

33
# https://www.nuget.org/packages/dotnet-script/
44
RUN dotnet tool install dotnet-script --tool-path /usr/bin

src/Dotnet.Script.Core/ScriptDownloader.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.IO;
3+
using System.IO.Compression;
34
using System.Net;
45
using System.Net.Http;
5-
using System.Net.Mime;
66
using System.Threading.Tasks;
77

88
namespace Dotnet.Script.Core
@@ -11,7 +11,6 @@ public class ScriptDownloader
1111
{
1212
public async Task<string> Download(string uri)
1313
{
14-
const string plainTextMediaType = "text/plain";
1514
using (HttpClient client = new HttpClient(new HttpClientHandler
1615
{
1716
// Avoid Deflate due to bugs. For more info, see:
@@ -25,14 +24,22 @@ public async Task<string> Download(string uri)
2524

2625
using (HttpContent content = response.Content)
2726
{
28-
string mediaType = content.Headers.ContentType.MediaType;
29-
30-
if (string.IsNullOrWhiteSpace(mediaType) || mediaType.Equals(plainTextMediaType, StringComparison.InvariantCultureIgnoreCase))
27+
var mediaType = content.Headers.ContentType.MediaType?.ToLowerInvariant().Trim();
28+
switch (mediaType)
3129
{
32-
return await content.ReadAsStringAsync();
30+
case null:
31+
case "":
32+
case "text/plain":
33+
return await content.ReadAsStringAsync();
34+
case "application/gzip":
35+
case "application/x-gzip":
36+
using (var stream = await content.ReadAsStreamAsync())
37+
using (var gzip = new GZipStream(stream, CompressionMode.Decompress))
38+
using (var reader = new StreamReader(gzip))
39+
return await reader.ReadToEndAsync();
40+
default:
41+
throw new NotSupportedException($"The media type '{mediaType}' is not supported when executing a script over http/https");
3342
}
34-
35-
throw new NotSupportedException($"The media type '{mediaType}' is not supported when executing a script over http/https");
3643
}
3744
}
3845
}

src/Dotnet.Script.Tests/ScriptExecutionTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,15 @@ public void ShouldSupportInlineNugetReferencesWithTrailingSemicoloninEvaluatedCo
241241
Assert.Contains("AutoMapper.MapperConfiguration", result.output);
242242
}
243243

244-
[Fact]
245-
public void ShouldExecuteRemoteScript()
244+
[Theory]
245+
[InlineData("https://gist.githubusercontent.com/seesharper/5d6859509ea8364a1fdf66bbf5b7923d/raw/0a32bac2c3ea807f9379a38e251d93e39c8131cb/HelloWorld.csx",
246+
"Hello World")]
247+
[InlineData("https://github.com/filipw/dotnet-script/files/5035247/hello.csx.gz",
248+
"Hello, world!")]
249+
public void ShouldExecuteRemoteScript(string url, string output)
246250
{
247-
var url = "https://gist.githubusercontent.com/seesharper/5d6859509ea8364a1fdf66bbf5b7923d/raw/0a32bac2c3ea807f9379a38e251d93e39c8131cb/HelloWorld.csx";
248251
var result = ScriptTestRunner.Default.Execute(url);
249-
Assert.Contains("Hello World", result.output);
252+
Assert.Contains(output, result.output);
250253
}
251254

252255
[Fact]

0 commit comments

Comments
 (0)
0