mockstack 0.11.0__tar.gz → 0.11.2__tar.gz
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.
- {mockstack-0.11.0 → mockstack-0.11.2}/PKG-INFO +1 -1
- {mockstack-0.11.0 → mockstack-0.11.2}/mkdocs.yml +1 -1
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/rules.py +6 -1
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/strategies/proxyrules.py +5 -2
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/strategies/test_proxyrules.py +13 -10
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack.egg-info/PKG-INFO +1 -1
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack.egg-info/SOURCES.txt +0 -1
- mockstack-0.11.0/.github/workflows/publish-to-dockerhub.yml +0 -58
- {mockstack-0.11.0 → mockstack-0.11.2}/.dockerignore +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/.env.example +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/.github/workflows/ci.yml +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/.github/workflows/publish-docs.yml +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/.github/workflows/publish-to-pypi.yml +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/.gitignore +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/.pre-commit-config.yaml +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/CODE_OF_CONDUCT.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/CONTRIBUTING.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/Dockerfile +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/LICENSE +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/README.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/SECURITY.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/docker-entrypoint.sh +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/docs/assets/favicon.ico +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/docs/assets/logo.png +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/docs/assets/mockstack.png +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/docs/configuration.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/docs/ollama.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/docs/strategies/base.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/docs/strategies/filefixtures.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/docs/strategies/proxyrules.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/examples/filefixtures-with-templates/.env.example +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/examples/filefixtures-with-templates/README.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/examples/filefixtures-with-templates/templates/servicename-api-v1-items.j2 +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/examples/filefixtures-with-templates/templates/servicename2-api-v2-user.533ec889-7c68-45c8-b21e-4a7e455d1234.j2 +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/examples/llm/README.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/examples/llm/mockstack-langchain-example.ipynb +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/examples/llm/templates/ollama-openai-v1-chat-completions.j2 +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/examples/llm/templates/openai-v1-chat-completions.j2 +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/examples/llm/templates/openai-v1-deployments-gpt-4o-chat-completions.j2 +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/examples/proxyrules-with-rules-file/.env.example +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/examples/proxyrules-with-rules-file/README.md +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/examples/proxyrules-with-rules-file/rules.yml +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/__init__.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/config.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/constants.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/display.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/exceptions.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/identifiers.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/intent.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/lifespan.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/llm/__init__.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/llm/ollama.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/main.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/middleware.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/routers/__init__.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/routers/catchall.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/routers/homepage.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/strategies/__init__.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/strategies/base.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/strategies/create_mixin.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/strategies/factory.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/strategies/filefixtures.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/telemetry.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/templating.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/__init__.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/conftest.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/fixtures/__init__.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/fixtures/proxyrules.yml +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/fixtures/templates/__init__.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/fixtures/templates/example-template.j2 +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/llm/__init__.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/llm/test_ollama.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/routers/__init__.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/routers/test_catchall.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/routers/test_homepage.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/strategies/__init__.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/strategies/test_create_mixin.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/strategies/test_filefixtures.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/test_display.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/test_identifiers.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/test_intent.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/test_middleware.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/test_rules.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/test_telemetry.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/test_templating.py +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack.egg-info/dependency_links.txt +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack.egg-info/entry_points.txt +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack.egg-info/requires.txt +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/mockstack.egg-info/top_level.txt +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/pyproject.toml +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/setup.cfg +0 -0
- {mockstack-0.11.0 → mockstack-0.11.2}/uv.lock +0 -0
|
@@ -4,6 +4,7 @@ import re
|
|
|
4
4
|
from abc import ABC, abstractmethod
|
|
5
5
|
from dataclasses import dataclass
|
|
6
6
|
from typing import Self
|
|
7
|
+
from urllib.parse import quote
|
|
7
8
|
|
|
8
9
|
from fastapi import Request
|
|
9
10
|
|
|
@@ -75,7 +76,11 @@ class Rule:
|
|
|
75
76
|
|
|
76
77
|
def apply(self, request: Request) -> RuleResult:
|
|
77
78
|
"""Apply the rule to the request."""
|
|
78
|
-
path = request.url.path
|
|
79
|
+
path = f"{request.url.path}"
|
|
80
|
+
if request.url.fragment:
|
|
81
|
+
# If a URL fragment component is present, we URL encode it and include it in the path to proxy.
|
|
82
|
+
path += quote("#") + request.url.fragment
|
|
83
|
+
|
|
79
84
|
result = self._url_for(path)
|
|
80
85
|
|
|
81
86
|
# Check if the replacement is a file template
|
|
@@ -25,7 +25,7 @@ from mockstack.templating import templates_env_provider
|
|
|
25
25
|
def maybe_update_response_headers(
|
|
26
26
|
response_headers: ResponseHeaders,
|
|
27
27
|
*,
|
|
28
|
-
|
|
28
|
+
content_length: int,
|
|
29
29
|
) -> ResponseHeaders:
|
|
30
30
|
"""Update the response headers if needed, e.g. to adjust for compression etc."""
|
|
31
31
|
_headers = response_headers.copy()
|
|
@@ -34,6 +34,8 @@ def maybe_update_response_headers(
|
|
|
34
34
|
# If the response is compressed, we need to remove the content-encoding header
|
|
35
35
|
# since httpx will automatically decompress the response while proxying.
|
|
36
36
|
_headers["content-encoding"] = "identity"
|
|
37
|
+
# content length needs to be adjusted as well for uncompressed content.
|
|
38
|
+
_headers["content-length"] = str(content_length)
|
|
37
39
|
|
|
38
40
|
return _headers
|
|
39
41
|
|
|
@@ -209,9 +211,10 @@ class ProxyRulesStrategy(BaseStrategy, CreateMixin):
|
|
|
209
211
|
|
|
210
212
|
resp = await client.send(req, stream=False)
|
|
211
213
|
content = resp.read()
|
|
214
|
+
|
|
212
215
|
response_headers = maybe_update_response_headers(
|
|
213
216
|
resp.headers,
|
|
214
|
-
|
|
217
|
+
content_length=len(content),
|
|
215
218
|
)
|
|
216
219
|
|
|
217
220
|
return Response(
|
|
@@ -359,15 +359,18 @@ async def test_proxy_rules_strategy_reverse_proxy(settings_reverse_proxy, span):
|
|
|
359
359
|
|
|
360
360
|
mock_client.send.assert_called_once()
|
|
361
361
|
|
|
362
|
-
def test_maybe_update_response_headers_updates_content_encoding():
|
|
363
|
-
"""Test maybe_update_response_headers updates content-encoding."""
|
|
364
|
-
headers = Headers(
|
|
365
|
-
{"content-encoding": "gzip", "content-type": "application/json"}
|
|
366
|
-
)
|
|
367
|
-
request_headers = Headers({"accept-encoding": "gzip"})
|
|
368
362
|
|
|
369
|
-
|
|
363
|
+
def test_maybe_update_response_headers_updates_content_encoding():
|
|
364
|
+
"""Test maybe_update_response_headers updates content-encoding."""
|
|
365
|
+
response_headers = httpx.Headers(
|
|
366
|
+
{"content-encoding": "gzip", "content-type": "application/json"}
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
updated_headers = maybe_update_response_headers(
|
|
370
|
+
response_headers=response_headers,
|
|
371
|
+
content_length=100,
|
|
372
|
+
)
|
|
370
373
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
+
assert updated_headers["content-encoding"] == "identity"
|
|
375
|
+
assert updated_headers["content-type"] == "application/json"
|
|
376
|
+
assert updated_headers["content-length"] == "100"
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
name: Publish Docker image to DockerHub
|
|
2
|
-
|
|
3
|
-
permissions:
|
|
4
|
-
contents: read
|
|
5
|
-
pull-requests: write
|
|
6
|
-
|
|
7
|
-
on:
|
|
8
|
-
push:
|
|
9
|
-
branches:
|
|
10
|
-
- "**"
|
|
11
|
-
tags:
|
|
12
|
-
- "*.*.*"
|
|
13
|
-
release:
|
|
14
|
-
types: [published]
|
|
15
|
-
pull_request:
|
|
16
|
-
|
|
17
|
-
jobs:
|
|
18
|
-
docker:
|
|
19
|
-
runs-on: ubuntu-latest
|
|
20
|
-
steps:
|
|
21
|
-
- name: Docker meta
|
|
22
|
-
id: meta
|
|
23
|
-
uses: docker/metadata-action@v5
|
|
24
|
-
with:
|
|
25
|
-
# list of Docker images to use as base name for tags
|
|
26
|
-
images: |
|
|
27
|
-
mockstack/mockstack
|
|
28
|
-
# generate Docker tags based on the following events/attributes
|
|
29
|
-
tags: |
|
|
30
|
-
type=ref,event=branch
|
|
31
|
-
type=ref,event=pr
|
|
32
|
-
type=semver,pattern={{version}}
|
|
33
|
-
type=semver,pattern={{major}}.{{minor}}
|
|
34
|
-
type=semver,pattern={{major}}
|
|
35
|
-
type=sha
|
|
36
|
-
|
|
37
|
-
- name: Login to Docker Hub
|
|
38
|
-
if: github.event_name != 'pull_request'
|
|
39
|
-
uses: docker/login-action@v3
|
|
40
|
-
with:
|
|
41
|
-
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
42
|
-
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
43
|
-
|
|
44
|
-
- name: Set up QEMU
|
|
45
|
-
uses: docker/setup-qemu-action@v3
|
|
46
|
-
|
|
47
|
-
- name: Set up Docker Buildx
|
|
48
|
-
uses: docker/setup-buildx-action@v3
|
|
49
|
-
|
|
50
|
-
- name: Build and push
|
|
51
|
-
uses: docker/build-push-action@v6
|
|
52
|
-
with:
|
|
53
|
-
build-args: |
|
|
54
|
-
MOCKSTACK_VERSION=${{ github.event_name == 'release' && github.ref_name || format('0.0.0+dev.{0}', github.sha) }}
|
|
55
|
-
platforms: linux/amd64,linux/arm64
|
|
56
|
-
push: ${{ github.event_name == 'release' }}
|
|
57
|
-
tags: ${{ steps.meta.outputs.tags }}
|
|
58
|
-
labels: ${{ steps.meta.outputs.labels }}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mockstack-0.11.0 → mockstack-0.11.2}/examples/llm/templates/ollama-openai-v1-chat-completions.j2
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mockstack-0.11.0 → mockstack-0.11.2}/mockstack/tests/fixtures/templates/example-template.j2
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|