Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/static/probe/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ window.ProbeRender = (function () {
'COOK-ECHO': '/docs/cookies/echo/',
'COOK-OVERSIZED': '/docs/cookies/oversized/',
'COOK-EMPTY': '/docs/cookies/empty/',
'COOK-NUL': '/docs/cookies/nul/',
'COOK-NUL': '/docs/cookies/null/',
'COOK-CONTROL-CHARS': '/docs/cookies/control-chars/',
'COOK-MANY-PAIRS': '/docs/cookies/many-pairs/',
'COOK-MALFORMED': '/docs/cookies/malformed/',
Expand Down
5 changes: 5 additions & 0 deletions src/Servers/FastPySGI-Server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM python:3.12-slim
WORKDIR /app
RUN pip install --no-cache-dir fastpysgi
COPY src/Servers/FastPySGI-Server/app.py .
ENTRYPOINT ["python3", "app.py", "8080"]
51 changes: 51 additions & 0 deletions src/Servers/FastPySGI-Server/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import fastpysgi

def app(environ, start_response):

Check failure on line 3 in src/Servers/FastPySGI-Server/app.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 29 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=MDA2AV_Http11Probe&issues=AZ1nndPErTtAswwgmIpu&open=AZ1nndPErTtAswwgmIpu&pullRequest=114
path = environ["PATH_INFO"]
req_method = environ.get('REQUEST_METHOD', '')

if path == '/cookie':
cookie_str = environ.get('HTTP_COOKIE', '')
lines = [ ]
for pair in cookie_str.split(';'):
pair = pair.strip()
eq = pair.find('=')
if eq > 0:
lines.append(f"{pair[:eq]}={pair[eq+1:]}")
body = '\n'.join(lines) + '\n' if lines else ''
start_response('200 OK', [ ('Content-Type', 'text/plain') ])

Check failure on line 16 in src/Servers/FastPySGI-Server/app.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal '200 OK' 4 times.

See more on https://sonarcloud.io/project/issues?id=MDA2AV_Http11Probe&issues=AZ1nndPErTtAswwgmIpt&open=AZ1nndPErTtAswwgmIpt&pullRequest=114

Check failure on line 16 in src/Servers/FastPySGI-Server/app.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal 'text/plain' 4 times.

See more on https://sonarcloud.io/project/issues?id=MDA2AV_Http11Probe&issues=AZ1nndPErTtAswwgmIps&open=AZ1nndPErTtAswwgmIps&pullRequest=114
return [ body.encode() ]

if path == '/echo':
lines = [ ]
for key, value in environ.items():
header_name = None
if key.startswith('HTTP_'):
header_name = key[5:]
if key == 'CONTENT_TYPE':
header_name = 'Content-Type'
if key == 'CONTENT_LENGTH':
header_name = 'Content-Length'
if header_name:
header_name = header_name.replace('_', '-').title()
lines.append(f"{header_name}: {value}")
body = '\n'.join(lines) + '\n'
start_response('200 OK', [ ('Content-Type', 'text/plain') ])
return [ body.encode() ]

if req_method == 'POST':
try:
length = int(environ.get('CONTENT_LENGTH', 0) or 0)
except ValueError:
length = 0
body = environ['wsgi.input'].read(length) if length > 0 else b''
start_response('200 OK', [ ('Content-Type', 'text/plain') ])
return [ body ]

start_response('200 OK', [ ('Content-Type', 'text/plain') ])
return [ b'OK' ]

if __name__ == "__main__":
import sys
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8080
fastpysgi.run(app, host="0.0.0.0", port=port, loglevel=0)
4 changes: 4 additions & 0 deletions src/Servers/FastPySGI-Server/probe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "FastPySGI",
"language": "Python"
}
Loading