forked from EvilBeaver/OneScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpRequestWrapper.cs
More file actions
139 lines (121 loc) · 4.95 KB
/
HttpRequestWrapper.cs
File metadata and controls
139 lines (121 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*----------------------------------------------------------
This Source Code Form is subject to the terms of the
Mozilla Public License, v.2.0. If a copy of the MPL
was not distributed with this file, You can obtain one
at http://mozilla.org/MPL/2.0/.
----------------------------------------------------------*/
using Microsoft.AspNetCore.Http;
using OneScript.Contexts;
using OneScript.StandardLibrary.Binary;
using OneScript.Values;
using ScriptEngine.Machine;
using ScriptEngine.Machine.Contexts;
using OneScript.StandardLibrary.Collections;
namespace OneScript.Web.Server
{
[ContextClass("HTTPСервисЗапрос", "HTTPServiceRequest")]
public class HttpRequestWrapper : AutoContext<HttpRequestWrapper>
{
private readonly HttpRequest _request;
private readonly PropertyWrappersCollection _wrappers = new ();
public HttpRequestWrapper(HttpRequest request)
{
_request = request;
}
[ContextProperty("Параметры", "Parameters", CanWrite = false)]
public FixedMapImpl Query => _wrappers.Get(nameof(Query), () => _request.Query.ToFixedMap());
[ContextProperty("ЕстьФормыВТипеКонтента", "HasFormContentType", CanWrite = false)]
public bool HasFormContentType => _request.HasFormContentType;
[ContextProperty("Тело", "Body", CanWrite = false)]
public GenericStream Body => _wrappers.Get(nameof(Body), () => new GenericStream(_request.Body));
[ContextProperty("ТипКонтента", "ContentType", CanWrite = false)]
public IValue ContentType
{
get
{
if (_request.ContentType == null)
return BslUndefinedValue.Instance;
else
return BslStringValue.Create(_request.ContentType);
}
}
[ContextProperty("ДлинаКонтента", "ContentLength", CanWrite = false)]
public IValue ContentLength
{
get
{
if (_request.ContentLength == null)
return BslUndefinedValue.Instance;
else
return BslNumericValue.Create((decimal)_request.ContentLength);
}
}
[ContextProperty("Куки", "Cookie", CanWrite = false)]
public RequestCookieCollectionWrapper Cookies => _wrappers.Get(nameof(Cookies), () => new RequestCookieCollectionWrapper(_request.Cookies));
[ContextProperty("Заголовки", "Headers", CanWrite = false)]
public HeaderDictionaryWrapper Headers => _wrappers.Get(nameof(Headers), () => new HeaderDictionaryWrapper(_request.Headers));
[ContextProperty("Протокол", "Protocol", CanWrite = false)]
public string Protocol => _request.Protocol;
[ContextProperty("СтрокаПараметров", "ParametersString", CanWrite = false)]
public IValue QueryString
{
get
{
if (_request.QueryString.HasValue)
return BslStringValue.Create(_request.QueryString.Value);
else
return BslUndefinedValue.Instance;
}
}
[ContextProperty("Путь", "Path", CanWrite = false)]
public IValue Path
{
get
{
if (_request.Path.HasValue)
return BslStringValue.Create(_request.Path.Value);
else
return BslUndefinedValue.Instance;
}
}
[ContextProperty("БазовыйПуть", "PathBase", CanWrite = false)]
public IValue PathBase
{
get
{
if (_request.PathBase.HasValue)
return BslStringValue.Create(_request.PathBase);
else
return BslUndefinedValue.Instance;
}
}
[ContextProperty("Хост", "Host", CanWrite = false)]
public IValue Host
{
get
{
if (_request.Host.HasValue)
return BslStringValue.Create(_request.Host.Value);
else
return BslUndefinedValue.Instance;
}
}
[ContextProperty("ЭтоHttps", "IsHttps", CanWrite = false)]
public bool IsHttps => _request.IsHttps;
[ContextProperty("Схема", "Scheme", CanWrite = false)]
public string Scheme => _request.Scheme;
[ContextProperty("Метод", "Method", CanWrite = false)]
public string Method => _request.Method;
[ContextProperty("Форма", "Form", CanWrite = false)]
public IValue Form
{
get
{
if (_request.HasFormContentType)
return _wrappers.Get(nameof(Form), () => new FormCollectionWrapper(_request.Form));
else
return BslUndefinedValue.Instance;
}
}
}
}