Skip to content

Commit 84a50c5

Browse files
authored
Merge pull request #45 from WeihanLi/dev
0.4.3
2 parents 2928df0 + cfe8c09 commit 84a50c5

File tree

7 files changed

+30
-6
lines changed

7 files changed

+30
-6
lines changed

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<LangVersion>latest</LangVersion>
3+
<LangVersion>preview</LangVersion>
44
<Nullable>enable</Nullable>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<PackageIcon>icon.png</PackageIcon>
@@ -9,7 +9,7 @@
99
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1010
<RepositoryType>git</RepositoryType>
1111
<RepositoryUrl>https://github.com/WeihanLi/dotnet-httpie</RepositoryUrl>
12-
<Product>dotnet-HTTPie</Product>
12+
<Product>dotnet-httpie</Product>
1313
<Authors>WeihanLi</Authors>
1414
<Copyright>Copyright 2021-$([System.DateTime]::Now.Year) (c) WeihanLi</Copyright>
1515
</PropertyGroup>

build/version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<VersionMajor>0</VersionMajor>
44
<VersionMinor>4</VersionMinor>
5-
<VersionPatch>2</VersionPatch>
5+
<VersionPatch>3</VersionPatch>
66
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
77
<InformationalVersion>$(PackageVersion)</InformationalVersion>
88
</PropertyGroup>

src/HTTPie/HTTPie.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
2222
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
2323
<PackageReference Include="WeihanLi.Common" Version="1.0.51" />
24-
<PackageReference Include="WeihanLi.Npoi" Version="2.0.1" />
24+
<PackageReference Include="WeihanLi.Npoi" Version="2.0.2" />
2525
</ItemGroup>
2626
</Project>

src/HTTPie/Middleware/DownloadMiddleware.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ public sealed class DownloadMiddleware : IResponseMiddleware
1313
public static readonly Option DownloadOption = new(new[] { "-d", "--download" }, "Download file");
1414
private static readonly Option ContinueOption = new(new[] { "-c", "--continue" }, "Download file using append mode");
1515
private static readonly Option<string> OutputOption = new(new[] { "-o", "--output" }, "Output file path");
16+
private static readonly Option<string> CheckSumOption = new(new[] { "--checksum" }, "Checksum to validate");
17+
private static readonly Option<HashType> CheckSumAlgOption = new(new[] { "--checksum-alg" }, () => HashType.SHA1, "Checksum hash algorithm type");
1618

1719
public ICollection<Option> SupportedOptions()
1820
{
19-
return new[] { DownloadOption, ContinueOption, OutputOption };
21+
return new[] { DownloadOption, ContinueOption, OutputOption, CheckSumOption, CheckSumAlgOption };
2022
}
2123

2224
public async Task Invoke(HttpContext context, Func<Task> next)
2325
{
2426
var download = context.Request.ParseResult.HasOption(DownloadOption);
2527
if (!download)
2628
{
29+
await next();
2730
return;
2831
}
2932
var output = context.Request.ParseResult.GetValueForOption(OutputOption);
@@ -51,6 +54,16 @@ public async Task Invoke(HttpContext context, Func<Task> next)
5154
{
5255
await File.WriteAllBytesAsync(fileName, context.Response.Bytes).ConfigureAwait(false);
5356
}
57+
58+
var checksum = context.Request.ParseResult.GetValueForOption(CheckSumOption);
59+
if (checksum.IsNotNullOrWhiteSpace())
60+
{
61+
var checksumAlgType = context.Request.ParseResult.GetValueForOption(CheckSumAlgOption);
62+
var calculatedValue = HashHelper.GetHashedString(checksumAlgType, context.Response.Bytes);
63+
var checksumMatched = calculatedValue.EqualsIgnoreCase(checksum);
64+
context.Response.Headers.TryAdd(Constants.ResponseCheckSumValueHeaderName, calculatedValue);
65+
context.Response.Headers.TryAdd(Constants.ResponseCheckSumValidHeaderName, checksumMatched.ToString());
66+
}
5467
await next();
5568
}
5669

src/HTTPie/Properties/launchSettings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
"proxy-test": {
4444
"commandName": "Project",
4545
"commandLineArgs": "https://www.nuget.org/profiles/weihanli/avatar?imageSize=512 --proxy=socks5://172.16.80.136:3389 -v"
46+
},
47+
"HTTPie-download-with-checksum": {
48+
"commandName": "Project",
49+
"commandLineArgs": "-v https://www.nuget.org/profiles/weihanli/avatar?imageSize=512 -d --checksum 1234"
50+
},
51+
"HTTPie-download-with-checksum-alg": {
52+
"commandName": "Project",
53+
"commandLineArgs": "-v https://www.nuget.org/profiles/weihanli/avatar?imageSize=512 -d --checksum 1234 --checksum-alg=md5"
4654
}
4755
}
4856
}

src/HTTPie/Utilities/Constants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static class Constants
2323
public const string ResponseTimestampHeaderName = $"X-{ApplicationName}-ResponseTimestamp";
2424
public const string RequestDurationHeaderName = $"X-{ApplicationName}-Duration";
2525

26+
public const string ResponseCheckSumValueHeaderName = $"X-{ApplicationName}-CheckSum-Value";
27+
public const string ResponseCheckSumValidHeaderName = $"X-{ApplicationName}-CheckSum-Valid";
28+
2629
#pragma warning disable 8602
2730
private static readonly string AppVersion = typeof(Constants).Assembly.GetName().Version.ToString(3);
2831
#pragma warning restore 8602

tests/HTTPie.UnitTest/HTTPie.UnitTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<PackageReference Include="FluentAssertions" Version="6.6.0" />
1717
<PackageReference Include="Moq" Version="4.17.2" />
1818
<PackageReference Include="xunit" Version="2.4.1" />
19-
<PackageReference Include="Xunit.DependencyInjection" Version="8.4.1" />
19+
<PackageReference Include="Xunit.DependencyInjection" Version="8.5.0" />
2020
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2222
<PrivateAssets>all</PrivateAssets>

0 commit comments

Comments
 (0)