GNServer 0.0.0.0.43__py3-none-any.whl → 0.0.0.0.45__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
GNServer/_app.py CHANGED
@@ -7,8 +7,7 @@ import asyncio
7
7
  import inspect
8
8
  import traceback
9
9
  import datetime
10
- from typing import Any, Callable, Dict, List, Optional, Pattern, Tuple, Union, AsyncGenerator
11
- from dataclasses import dataclass
10
+ from typing import Any, Callable, Dict, List, Optional, Tuple, Union, AsyncGenerator
12
11
  from aioquic.asyncio.server import serve
13
12
  from aioquic.asyncio.protocol import QuicConnectionProtocol
14
13
  from aioquic.quic.configuration import QuicConfiguration
@@ -113,9 +112,6 @@ def guess_type(filename: str) -> str:
113
112
 
114
113
 
115
114
 
116
-
117
-
118
-
119
115
  class App:
120
116
  def __init__(self):
121
117
  self._routes: List[Route] = []
@@ -192,9 +188,6 @@ class App:
192
188
  else:
193
189
  await func()
194
190
 
195
-
196
-
197
-
198
191
 
199
192
 
200
193
  async def dispatchRequest(
@@ -214,13 +207,7 @@ class App:
214
207
  if r.method != method:
215
208
  continue
216
209
 
217
- if r.cors is not None and r.cors.allow_origins is not None:
218
- if request._origin is None:
219
- return GNResponse("gn:backend:801", {'error': 'Cors error. Route has cors but request has no origin url.'})
220
- if not resolve_cors(request._origin, r.cors.allow_origins):
221
- return GNResponse("gn:backend:802", {'error': 'Cors error: origin'})
222
- if r.cors.allow_methods is not None and request.method not in r.cors.allow_methods and '*' not in r.cors.allow_methods:
223
- return GNResponse("gn:backend:803", {'error': 'Cors error: method'})
210
+ resolve_cors(request, r.cors)
224
211
 
225
212
  sig = inspect.signature(r.handler)
226
213
  def _ann(name: str):
@@ -261,14 +248,8 @@ class App:
261
248
  else:
262
249
  result._cors = r.cors
263
250
 
264
- if result._cors is not None and result._cors != r.cors and result._cors.allow_origins is not None:
265
- if request._origin is None:
266
- print(result._cors.allow_origins)
267
- return GNResponse("gn:backend:801", {'error': 'Cors error. Route has cors but request has no origin url. [2]'})
268
- if not resolve_cors(request._origin, result._cors.allow_origins):
269
- return GNResponse("gn:backend:802", {'error': 'Cors error: origin'})
270
- if result._cors.allow_methods is not None and request.method not in result._cors.allow_methods and '*' not in result._cors.allow_methods:
271
- return GNResponse("gn:backend:803", {'error': 'Cors error: method'})
251
+ resolve_cors(request, result._cors)
252
+
272
253
  return result
273
254
  else:
274
255
  raise TypeError(
@@ -342,8 +323,8 @@ class App:
342
323
  # получаем длинну пакета
343
324
  mode, stream, lenght = GNRequest.type(buf)
344
325
 
345
- if mode not in (1, 2): # не наш пакет
346
- logger.debug(f'Пакет отклонен: mode пакета {mode}. Разрешен 1, 2')
326
+ if mode not in (1, 2, 4): # не наш пакет
327
+ logger.debug(f'Пакет отклонен: mode пакета {mode}. Разрешен 1, 2, 3')
347
328
  return
348
329
 
349
330
  if not stream: # если не стрим, то ждем конец quic стрима и запускаем обработку ответа
@@ -1,8 +1,11 @@
1
1
 
2
2
  import re
3
+ from typing import Optional
3
4
  from urllib.parse import urlparse
5
+ from gnobjects.net.objects import GNRequest, CORSObject
6
+ from gnobjects.net.fastcommands import AllGNFastCommands
4
7
 
5
- def resolve_cors(origin_url: str, rules: list[str]) -> bool:
8
+ def _resolve_cors(origin_url: str, rules: list[str]) -> bool:
6
9
  """
7
10
  Возвращает origin_url если он матчится хотя бы с одним правилом.
8
11
  Правила:
@@ -126,4 +129,28 @@ def _host_matches_pattern(host: str, pattern: str) -> bool:
126
129
  return match(hi + 1, pi + 1)
127
130
  return False
128
131
 
129
- return match(0, 0)
132
+ return match(0, 0)
133
+
134
+
135
+
136
+ def resolve_cors(request: GNRequest, cors: Optional[CORSObject]):
137
+ if cors is None:
138
+ return
139
+
140
+ if request.client.type not in cors.allow_client_types:
141
+ raise AllGNFastCommands.CorsClientTypeNotAllowed()
142
+
143
+ if cors.allow_origins is not None:
144
+ if request._origin is None:
145
+ raise AllGNFastCommands.CorsOriginNotAllowed('Route has cors but request has no origin url')
146
+
147
+ if not _resolve_cors(request._origin, cors.allow_origins):
148
+ raise AllGNFastCommands.CorsOriginNotAllowed()
149
+
150
+ if cors.allow_methods is not None:
151
+ if request.method not in cors.allow_methods:
152
+ raise AllGNFastCommands.CorsMethodNotAllowed()
153
+
154
+ if cors.allow_transport_protocols is not None:
155
+ if request.transport in ('gn:quik:real', 'gn:quik:dev') and request.transport not in cors.allow_transport_protocols:
156
+ raise AllGNFastCommands.CorsTransportProtocolNotAllowed()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GNServer
3
- Version: 0.0.0.0.43
3
+ Version: 0.0.0.0.45
4
4
  Summary: GNServer
5
5
  Home-page: https://github.com/KeyisB/libs/tree/main/GNServer
6
6
  Author: KeyisB
@@ -1,13 +1,13 @@
1
1
  GNServer/__init__.py,sha256=6CMCZlkBO74PW8i8DAri5xz2fYM9EyPH8vdsLYBMmOo,1560
2
- GNServer/_app.py,sha256=nvK_9w1YtZfE-Xh0K-ebkvVINAx4Fir3NSw7Lbwyaz4,18874
2
+ GNServer/_app.py,sha256=4JCz2-MDKPbzu45iB8tYarYnfr1lP02B0KOrC1sSBP8,17489
3
3
  GNServer/_client.py,sha256=jABXjnNJ9o6Mo3jRTW5Qyb-yhgjdH4VnIexwOplJcyg,31867
4
- GNServer/_cors_resolver.py,sha256=U9IFGN7vpVsEM2smhuf5QGj8vYgs7HeFQwDdzWVVy9c,4832
4
+ GNServer/_cors_resolver.py,sha256=aDxk4ItaEK-6vlDbkno8FJZEjczGEe8vkOui6_kz5-Y,5950
5
5
  GNServer/_crt.py,sha256=SOmyX7zBiCY9EhVSekksQtBHgTIZVvdqNZ8Ni-E5Zow,1390
6
6
  GNServer/_func_params_validation.py,sha256=pDXRzPVTdPnDHFMMmKd014SConBjFOuaLeJTY0vldlM,11412
7
7
  GNServer/_routes.py,sha256=bJnmQ8uEhPVQgy2tTqE5TEIM8aFXV-lVI7c2nG0rQwk,3384
8
8
  GNServer/_template_resolver.py,sha256=vdJYb_7PjIeTWq-Clr7jyj7QIvPBxplU7EqeOuMJ64c,1409
9
- gnserver-0.0.0.0.43.dist-info/licenses/LICENSE,sha256=_rN-sb3LemR3cKsEqjJRdXkdt7mME1mkW1BwWEn-zAw,1309
10
- gnserver-0.0.0.0.43.dist-info/METADATA,sha256=24T_ROdMsk676KmLYK89nDqS5HxLMEs-lhn2xOcfRTs,830
11
- gnserver-0.0.0.0.43.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
- gnserver-0.0.0.0.43.dist-info/top_level.txt,sha256=-UOUBuD4u7Qkb1o5PdcwyA3kx8xCH2lwy0tJHi26Wb4,9
13
- gnserver-0.0.0.0.43.dist-info/RECORD,,
9
+ gnserver-0.0.0.0.45.dist-info/licenses/LICENSE,sha256=_rN-sb3LemR3cKsEqjJRdXkdt7mME1mkW1BwWEn-zAw,1309
10
+ gnserver-0.0.0.0.45.dist-info/METADATA,sha256=_WEuY_pNTQNaJZ_fVQjgLw5zmcYO44bokVAGKxbj_Ps,830
11
+ gnserver-0.0.0.0.45.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ gnserver-0.0.0.0.45.dist-info/top_level.txt,sha256=-UOUBuD4u7Qkb1o5PdcwyA3kx8xCH2lwy0tJHi26Wb4,9
13
+ gnserver-0.0.0.0.45.dist-info/RECORD,,