-
Notifications
You must be signed in to change notification settings - Fork 318
feat: Optimize request validator + make thread safe (backwards compatible) #660
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
Merged
tiwarishubham635
merged 20 commits into
twilio:main
from
Swimburger:optimize-request-validation
Mar 21, 2025
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3a5b83e
Implement IDisposal for RequestValidator
benmccallum 2570c4f
Merge branch 'main' into patch-1
benmccallum c3c0166
fix: Make RequestValidator thread safe
benmccallum 48e66df
Remove IDisposable interface as not needed anymore
benmccallum 813a64b
Optimize request validator but keep backwards compatible
Swimburger 709f8b8
Merge
Swimburger e8a534f
Merge branch 'benmccallum-patch-1' into optimize-request-validation
Swimburger 43e433c
Reapply optimizations
Swimburger c22e4af
Add 6.0 TFM, empty <VersionSuffix> to fix solution, update test packages
Swimburger 7bf745b
Stop SecureCompare from being optimized
Swimburger 6d8f253
Merge branch 'main' into optimize-request-validation
Swimburger 26a8ea1
Merge branch 'main' into optimize-request-validation
Swimburger 2b26f8c
Merge branch 'main' of https://github.com/swimburger/twilio-csharp in…
Swimburger 7181df5
Use oneshot hash method for ValidateBody
Swimburger 45fd641
Merge branch 'main' into optimize-request-validation
Swimburger fb82543
Merge
Swimburger 6a8a44a
Update Twilio.Test.csproj
tiwarishubham635 76919f5
Update Twilio.csproj
tiwarishubham635 b542297
Merge branch 'main' into optimize-request-validation
tiwarishubham635 bf9fb33
chore: target net6.0
tiwarishubham635 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,3 +235,4 @@ html/ | |
|
|
||
| # sonar cloud stuff | ||
| .sonarqube | ||
| /test/Twilio.Benchmark/BenchmarkDotNet.Artifacts | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| using System.Collections.Specialized; | ||
| using BenchmarkDotNet.Attributes; | ||
| using BenchmarkDotNet.Running; | ||
| using Twilio.Security; | ||
|
|
||
| var summary = BenchmarkRunner.Run<RequestValidationBenchmark>(); | ||
| Console.Write(summary); | ||
|
|
||
| [MemoryDiagnoser] | ||
| public class RequestValidationBenchmark | ||
| { | ||
| private const string Secret = "12345"; | ||
| private const string UnhappyPathUrl = "HTTP://MyCompany.com:8080/myapp.php?foo=1&bar=2"; | ||
| private const string UnhappyPathSignature = "eYYN9fMlxrQMXOsr7bIzoPTrbxA="; | ||
| private const string HappyPathUrl = "https://mycompany.com/myapp.php?foo=1&bar=2"; | ||
| private const string HappyPathSignature = "3LL3BFKOcn80artVM5inMPFpmtU="; | ||
| private static readonly NameValueCollection UnhappyPathParameters = new() | ||
| { | ||
| {"ToCountry", "US"}, | ||
| {"ToState", "OH"}, | ||
| {"SmsMessageSid", "SMcea2a3bd6f50296f8fab60f377db03eb"}, | ||
| {"NumMedia", "0"}, | ||
| {"ToCity", "UTICA"}, | ||
| {"FromZip", "20705"}, | ||
| {"SmsSid", "SMcea2a3bd6f50296f8fab60f377db03eb"}, | ||
| {"FromState", "DC"}, | ||
| {"SmsStatus", "received"}, | ||
| {"FromCity", "BELTSVILLE"}, | ||
| {"Body", "Ahoy!"}, | ||
| {"FromCountry", "US"}, | ||
| {"To", "+10123456789"}, | ||
| {"ToZip", "43037"}, | ||
| {"NumSegments", "1"}, | ||
| {"ReferralNumMedia", "0"}, | ||
| {"MessageSid", "SMcea2a3bd6f50296f8fab60f377db03eb"}, | ||
| {"AccountSid", "ACe718619887aac3ee5b21edafbvsdf6h7fgb"}, | ||
| {"From", "+10123456789"}, | ||
| {"ApiVersion", "2010-04-01"} | ||
| }; | ||
| private static readonly Dictionary<string, string> HappyPathParameters = new() | ||
| { | ||
| {"ToCountry", "US"}, | ||
| {"ToState", "OH"}, | ||
| {"SmsMessageSid", "SMcea2a3bd6f50296f8fab60f377db03eb"}, | ||
| {"NumMedia", "0"}, | ||
| {"ToCity", "UTICA"}, | ||
| {"FromZip", "20705"}, | ||
| {"SmsSid", "SMcea2a3bd6f50296f8fab60f377db03eb"}, | ||
| {"FromState", "DC"}, | ||
| {"SmsStatus", "received"}, | ||
| {"FromCity", "BELTSVILLE"}, | ||
| {"Body", "Ahoy!"}, | ||
| {"FromCountry", "US"}, | ||
| {"To", "+10123456789"}, | ||
| {"ToZip", "43037"}, | ||
| {"NumSegments", "1"}, | ||
| {"ReferralNumMedia", "0"}, | ||
| {"MessageSid", "SMcea2a3bd6f50296f8fab60f377db03eb"}, | ||
| {"AccountSid", "ACe718619887aac3ee5b21edafbvsdf6h7fgb"}, | ||
| {"From", "+10123456789"}, | ||
| {"ApiVersion", "2010-04-01"} | ||
| }; | ||
|
|
||
|
|
||
| [Benchmark] | ||
| public void OriginalUnhappyPath() | ||
| { | ||
| var requestValidator = new RequestValidatorOriginal(Secret); | ||
| requestValidator.Validate(UnhappyPathUrl, UnhappyPathParameters, UnhappyPathSignature); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void CurrentUnhappyPath() | ||
| { | ||
| var requestValidator = new RequestValidator(Secret); | ||
| requestValidator.Validate(UnhappyPathUrl, UnhappyPathParameters, UnhappyPathSignature); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void OriginalHappyPath() | ||
| { | ||
| var requestValidator = new RequestValidatorOriginal(Secret); | ||
| requestValidator.Validate(HappyPathUrl, HappyPathParameters, HappyPathSignature); | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public void CurrentHappyPath() | ||
| { | ||
| var requestValidator = new RequestValidator(Secret); | ||
| requestValidator.Validate(HappyPathUrl, HappyPathParameters, HappyPathSignature); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.