-
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.
Add UI tests for request body compression
- Loading branch information
Showing
6 changed files
with
116 additions
and
3 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
32 changes: 32 additions & 0 deletions
32
src/Samples/Common/ViewModels/FeatureSamples/PostBack/RequestCompressionViewModel.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,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using DotVVM.Framework.Hosting; | ||
using DotVVM.Framework.ViewModel; | ||
|
||
namespace DotVVM.Samples.BasicSamples.ViewModels.FeatureSamples.PostBack | ||
{ | ||
public class RequestCompressionViewModel : DotvvmViewModelBase | ||
{ | ||
public string LargeField { get; set; } = new string('a', 100_000); | ||
|
||
[Bind(Direction.ServerToClientFirstRequest)] | ||
public int[] RequestSizes { get; set; } = new int[0]; | ||
[Bind(Direction.ServerToClientFirstRequest)] | ||
public int[] ResponseSizes { get; set; } = new int[0]; | ||
|
||
public void Command() | ||
{ | ||
LargeField += "b"; | ||
} | ||
|
||
[AllowStaticCommand] | ||
public static string StaticCommand(string data) | ||
{ | ||
return data + "c"; | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/Samples/Common/Views/FeatureSamples/PostBack/RequestCompression.dothtml
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,51 @@ | ||
@viewModel DotVVM.Samples.BasicSamples.ViewModels.FeatureSamples.PostBack.RequestCompressionViewModel | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title></title> | ||
</head> | ||
<body> | ||
<h1>POST Request Gzip Compression</h1> | ||
|
||
<p> | ||
LargeField.Length = <span InnerText={value: LargeField.Length} data-ui="field-length"></span> | ||
</p> | ||
<p> | ||
Request/Response Body size: | ||
<table> | ||
<dot:Repeater WrapperTagName="tr" DataSource={value: RequestSizes} > | ||
<td data-ui="request-size">{{value: _this}}</td> | ||
</dot:Repeater> | ||
<dot:Repeater WrapperTagName="tr" DataSource={value: ResponseSizes} > | ||
<td data-ui="response-size">{{value: _this}}</td> | ||
</dot:Repeater> | ||
</table> | ||
</p> | ||
|
||
<p> | ||
<dot:Button Click={command: Command()} data-ui="button-command">Command</dot:Button> | ||
<dot:Button Click={staticCommand: LargeField = RootViewModel.StaticCommand(LargeField)} data-ui="button-static-command"> StaticCommand</dot:Button> | ||
<dot:Button Click={staticCommand: LargeField = LargeField + "d"} data-ui="button-client-side">Client-side StaticCommand</dot:Button> | ||
</p> | ||
|
||
<script type="text/javascript"> | ||
const fetchBackup = window.fetch; | ||
window.fetch = function (url, init) { | ||
console.log('fetch', url, init); | ||
if (url == location.pathname && init.method == 'POST') { | ||
const size = init.body?.size ?? new Blob([init.body]).size; | ||
dotvvm.updateState(x => ({...x, RequestSizes: [...x.RequestSizes, size]})); | ||
} | ||
const result = fetchBackup.apply(window, arguments); | ||
// result.then(async response => { | ||
// const responseSize = response.headers.get('Content-Length') | ||
// dotvvm.updateState(x => ({...x, ResponseSizes: [...x.ResponseSizes, responseSize]})); | ||
// }); | ||
return result; | ||
}; | ||
</script> | ||
</body> | ||
</html> | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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