+95
-4
lines changedFilter options
+95
-4
lines changed Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
1
+
using Microsoft.AspNetCore.Builder;
2
+
using Microsoft.AspNetCore.Http;
3
+
using Microsoft.AspNetCore.WebUtilities;
4
+
using Microsoft.Net.Http.Headers;
5
+
using System.IO;
6
+
using System.Security.Cryptography;
7
+
using System.Threading;
8
+
using System.Threading.Tasks;
9
+
10
+
namespace Signum.React.Filters
11
+
{
12
+
public class ETagMiddleware
13
+
{
14
+
private readonly RequestDelegate _next;
15
+
16
+
public ETagMiddleware(RequestDelegate next)
17
+
{
18
+
_next = next;
19
+
}
20
+
21
+
public async Task InvokeAsync(HttpContext context)
22
+
{
23
+
var response = context.Response;
24
+
var originalStream = response.Body;
25
+
26
+
using (var ms = new MemoryStream())
27
+
{
28
+
response.Body = ms;
29
+
30
+
await _next(context);
31
+
32
+
if (IsEtagSupported(response))
33
+
{
34
+
string checksum = CalculateChecksum(ms);
35
+
36
+
response.Headers[HeaderNames.ETag] = checksum;
37
+
38
+
if (context.Request.Headers.TryGetValue(HeaderNames.IfNoneMatch, out var etag) && checksum == etag)
39
+
{
40
+
response.StatusCode = StatusCodes.Status304NotModified;
41
+
return;
42
+
}
43
+
}
44
+
45
+
ms.Position = 0;
46
+
await ms.CopyToAsync(originalStream);
47
+
}
48
+
}
49
+
50
+
private static bool IsEtagSupported(HttpResponse response)
51
+
{
52
+
if (response.StatusCode != StatusCodes.Status200OK)
53
+
return false;
54
+
55
+
// The 20kb length limit is not based in science. Feel free to change
56
+
if (response.Body.Length > 10 * 1024 * 1024)
57
+
return false;
58
+
59
+
if (response.Headers.ContainsKey(HeaderNames.ETag))
60
+
return false;
61
+
62
+
return true;
63
+
}
64
+
65
+
private static string CalculateChecksum(MemoryStream ms)
66
+
{
67
+
using (var algo = SHA1.Create())
68
+
{
69
+
ms.Position = 0;
70
+
byte[] bytes = algo.ComputeHash(ms);
71
+
return WebEncoders.Base64UrlEncode(bytes);
72
+
}
73
+
}
74
+
}
75
+
76
+
public static class ApplicationBuilderExtensions
77
+
{
78
+
public static void UseETagger(this IApplicationBuilder app)
79
+
{
80
+
app.UseMiddleware<ETagMiddleware>();
81
+
}
82
+
}
83
+
}
Original file line number Diff line number Diff line change
@@ -11,7 +11,10 @@ import { Entity, EntityPack, Lite, ModifiableEntity } from "./Signum.Entities";
11
11
12
12
Dic.skipClasses.push(React.Component);
13
13
14
-
14
+
export let currentCulture: string | undefined;
15
+
export function setCurrentCulture(culture: string | undefined) {
16
+
currentCulture = culture;
17
+
}
15
18
16
19
export let currentUser: IUserEntity | undefined;
17
20
export function setCurrentUser(user: IUserEntity | undefined) {
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ import { Dic } from './Globals';
4
4
import { ModifiableEntity, Entity, Lite, MListElement, ModelState, MixinEntity } from './Signum.Entities'; //ONLY TYPES or Cyclic problems in Webpack!
5
5
import { ajaxGet } from './Services';
6
6
import { MList } from "./Signum.Entities";
7
-
import QueryTokenBuilder from './SearchControl/QueryTokenBuilder';
8
-
import { AggregateType } from './FindOptions';
7
+
import * as AppContext from './AppContext';
8
+
import { QueryString } from './QueryString';
9
9
10
10
export function getEnumInfo(enumTypeName: string, enumId: number): MemberInfo {
11
11
@@ -427,7 +427,12 @@ export function isQueryDefined(queryName: PseudoType | QueryKey): boolean {
427
427
}
428
428
429
429
export function reloadTypes(): Promise<void> {
430
-
return ajaxGet<TypeInfoDictionary>({ url: "~/api/reflection/types" })
430
+
return ajaxGet<TypeInfoDictionary>({
431
+
url: "~/api/reflection/types?" + QueryString.stringify({
432
+
user: AppContext.currentUser?.id,
433
+
culture: AppContext.currentCulture
434
+
})
435
+
})
431
436
.then(types => {
432
437
setTypes(types);
433
438
onReloadTypes();
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4