This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Httpstress: Add checksum validation & support plaintext http #40360
Merged
eiriktsarpalis
merged 14 commits into
dotnet:master
from
eiriktsarpalis:httpstress-add-checksum-validation
Aug 22, 2019
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
33730a2
add checksum validation to duplex and header operations
eiriktsarpalis 7eb331e
add more descriptive errors to server checksums
eiriktsarpalis e4335ad
add divergence metadata
eiriktsarpalis cf43446
add timestamps to exception reporting
eiriktsarpalis 84f2194
add support for plaintext http
eiriktsarpalis 103bdb5
add trailing header validation logic
eiriktsarpalis 783eb71
bound size of request headers
eiriktsarpalis fd49524
add winhttphandler client support
eiriktsarpalis 31e7997
reduce content & header max size defaults
eiriktsarpalis 1f37f07
remove plugin artifact
eiriktsarpalis 3973cad
address style issues
eiriktsarpalis b4577e3
fix type error
eiriktsarpalis a4eaa37
remove ionide artifact
eiriktsarpalis 8777f07
remove CRC32.NET dependency
eiriktsarpalis 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
85 changes: 85 additions & 0 deletions
85
src/System.Net.Http/tests/StressTests/HttpStress/ChecksumHelpers.cs
This file contains 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,85 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace HttpStress | ||
{ | ||
// Adapted from https://github.com/dotnet/corefx/blob/41cd99d051102be4ed83f4f9105ae9e73aa48b7c/src/Common/tests/System/IO/Compression/CRC.cs | ||
public static class CRC | ||
{ | ||
// Table of CRCs of all 8-bit messages. | ||
private static ulong[] s_crc_table = new ulong[256]; | ||
public const ulong InitialCrc = 0xffffffffL; | ||
|
||
// Flag: has the table been computed? Initially false. | ||
private static bool s_crc_table_computed = false; | ||
|
||
// Make the table for a fast CRC. | ||
// Derivative work of zlib -- https://github.com/madler/zlib/blob/master/crc32.c (hint: L108) | ||
private static void make_crc_table() | ||
{ | ||
ulong c; | ||
int n, k; | ||
|
||
for (n = 0; n < 256; n++) | ||
{ | ||
c = (ulong)n; | ||
for (k = 0; k < 8; k++) | ||
{ | ||
if ((c & 1) > 0) | ||
c = 0xedb88320L ^ (c >> 1); | ||
else | ||
c = c >> 1; | ||
} | ||
s_crc_table[n] = c; | ||
} | ||
s_crc_table_computed = true; | ||
} | ||
|
||
// Update a running CRC with the bytes buf[0..len-1]--the CRC | ||
// should be initialized to all 1's, and the transmitted value | ||
// is the 1's complement of the final running CRC (see the | ||
// crc() routine below)). | ||
public static ulong update_crc(ulong crc, byte[] buf, int len) | ||
{ | ||
ulong c = crc; | ||
int n; | ||
|
||
if (!s_crc_table_computed) | ||
make_crc_table(); | ||
for (n = 0; n < len; n++) | ||
{ | ||
c = s_crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8); | ||
} | ||
return c; | ||
} | ||
|
||
public static ulong update_crc(ulong crc, string text, Encoding encoding = null) | ||
{ | ||
encoding = encoding ?? Encoding.ASCII; | ||
byte[] bytes = encoding.GetBytes(text); | ||
return update_crc(crc, bytes, bytes.Length); | ||
} | ||
|
||
public static ulong CalculateCRC(byte[] buf) => update_crc(InitialCrc, buf, buf.Length) ^ InitialCrc; | ||
|
||
public static ulong CalculateHeaderCrc<T>(IEnumerable<(string name, T)> headers, Encoding encoding = null) where T : IEnumerable<string> | ||
{ | ||
ulong checksum = InitialCrc; | ||
|
||
foreach ((string name, IEnumerable<string> values) in headers) | ||
{ | ||
checksum = update_crc(checksum, name); | ||
foreach (string value in values) | ||
{ | ||
checksum = update_crc(checksum, value); | ||
} | ||
} | ||
|
||
return checksum ^ InitialCrc; | ||
} | ||
} | ||
} |
160 changes: 112 additions & 48 deletions
160
src/System.Net.Http/tests/StressTests/HttpStress/ClientOperations.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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
Oops, something went wrong.
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.