-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1766 from riganti/request-compression
gzip compression of command and staticCommand requests
- Loading branch information
Showing
31 changed files
with
1,970 additions
and
2,459 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace DotVVM.Framework.Utils | ||
{ | ||
internal class LimitLengthStream : Stream | ||
{ | ||
private readonly Stream innerStream; | ||
private readonly long maxLength; | ||
private readonly string comment; | ||
private long position; | ||
|
||
public LimitLengthStream(Stream innerStream, long maxLength, string errorComment) | ||
{ | ||
this.innerStream = innerStream; | ||
this.maxLength = maxLength; | ||
this.comment = errorComment; | ||
} | ||
|
||
private void MovePosition(long offset) | ||
{ | ||
position += offset; | ||
if (position > maxLength) | ||
throw new InvalidOperationException($"The stream is limited to {maxLength} bytes: {comment}"); | ||
} | ||
|
||
public long RemainingAllowedLength => maxLength - position; | ||
|
||
|
||
public override bool CanRead => innerStream.CanRead; | ||
|
||
public override bool CanSeek => false; | ||
|
||
public override bool CanWrite => false; | ||
|
||
public override long Length => innerStream.Length; | ||
|
||
public override long Position | ||
{ | ||
get => innerStream.Position; | ||
set => throw new NotImplementedException(); | ||
} | ||
|
||
public override void Flush() => innerStream.Flush(); | ||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
var read = innerStream.Read(buffer, offset, (int)Math.Min(count, RemainingAllowedLength + 1)); | ||
MovePosition(read); | ||
return read; | ||
} | ||
|
||
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) | ||
{ | ||
var read = await innerStream.ReadAsync(buffer, offset, (int)Math.Min(count, RemainingAllowedLength + 1), cancellationToken); | ||
MovePosition(read); | ||
return read; | ||
} | ||
#if DotNetCore | ||
public override int Read(Span<byte> buffer) | ||
{ | ||
var read = innerStream.Read(buffer.Slice(0, (int)Math.Min(buffer.Length, RemainingAllowedLength + 1))); | ||
MovePosition(read); | ||
return read; | ||
} | ||
|
||
public override async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default) | ||
{ | ||
var read = await innerStream.ReadAsync(buffer.Slice(0, (int)Math.Min(buffer.Length, RemainingAllowedLength + 1)), cancellationToken); | ||
MovePosition(read); | ||
return read; | ||
} | ||
#endif | ||
public override long Seek(long offset, SeekOrigin origin) => throw new System.NotImplementedException(); | ||
public override void SetLength(long value) => throw new System.NotImplementedException(); | ||
public override void Write(byte[] buffer, int offset, int count) => throw new System.NotImplementedException(); | ||
|
||
public static Stream LimitLength(Stream s, long maxLength, string errorComment) | ||
{ | ||
if (maxLength < 0 || maxLength == long.MaxValue) | ||
return s; | ||
|
||
if (s.CanSeek) | ||
{ | ||
if (s.Length > maxLength) | ||
throw new InvalidOperationException($"The stream is limited to {maxLength} bytes: {errorComment}"); | ||
return s; | ||
} | ||
else | ||
{ | ||
return new LimitLengthStream(s, maxLength, errorComment); | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,20 @@ | |
"license": "Apache-2.0", | ||
"packageManager": "[email protected]", | ||
"devDependencies": { | ||
"@types/jest": "26.0.14", | ||
"@types/jest": "29.0.0", | ||
"@types/knockout": "^3.4.72", | ||
"esbuild": "^0.14.39", | ||
"@types/node": "20.11.5", | ||
"esbuild": "^0.19.11", | ||
"fast-check": "2.5.0", | ||
"jest": "26.5.3", | ||
"jest": "29.7.0", | ||
"jest-environment-jsdom": "29.7.0", | ||
"jest-github-actions-reporter": "^1.0.3", | ||
"jest-junit": "^14.0.1", | ||
"jest-junit": "^16.0.0", | ||
"promise": "8.1.0", | ||
"symbol-es6": "^0.1.2", | ||
"systemjs": "6.7.1", | ||
"ts-jest": "26.4.1", | ||
"typescript": "4.7.4" | ||
"ts-jest": "29.1.1", | ||
"typescript": "5.3.3" | ||
}, | ||
"scripts": { | ||
"build": "node ./build.js", | ||
|
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.