Skip to content

Commit 65fa3c6

Browse files
authored
Merge branch 'master' into early-rs-validation
2 parents 36aa4a3 + 75adbfd commit 65fa3c6

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,7 +1,7 @@
11
using System;
22
using System.IO;
3+
using System.IO.Compression;
34
using System.Net.Http;
4-
using System.Net.Mime;
55
using System.Threading.Tasks;
66

77
namespace Dotnet.Script.Core
@@ -10,7 +10,6 @@ public class ScriptDownloader
1010
{
1111
public async Task<string> Download(string uri)
1212
{
13-
const string plainTextMediaType = "text/plain";
1413
using (HttpClient client = new HttpClient())
1514
{
1615
using (HttpResponseMessage response = await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead))
@@ -19,14 +18,22 @@ public async Task<string> Download(string uri)
1918

2019
using (HttpContent content = response.Content)
2120
{
22-
string mediaType = content.Headers.ContentType.MediaType;
23-
24-
if (string.IsNullOrWhiteSpace(mediaType) || mediaType.Equals(plainTextMediaType, StringComparison.InvariantCultureIgnoreCase))
21+
var mediaType = content.Headers.ContentType.MediaType?.ToLowerInvariant().Trim();
22+
switch (mediaType)
2523
{
26-
return await content.ReadAsStringAsync();
24+
case null:
25+
case "":
26+
case "text/plain":
27+
return await content.ReadAsStringAsync();
28+
case "application/gzip":
29+
case "application/x-gzip":
30+
using (var stream = await content.ReadAsStreamAsync())
31+
using (var gzip = new GZipStream(stream, CompressionMode.Decompress))
32+
using (var reader = new StreamReader(gzip))
33+
return await reader.ReadToEndAsync();
34+
default:
35+
throw new NotSupportedException($"The media type '{mediaType}' is not supported when executing a script over http/https");
2736
}
28-
29-
throw new NotSupportedException($"The media type '{mediaType}' is not supported when executing a script over http/https");
3037
}
3138
}
3239
}

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)