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
4 changes: 2 additions & 2 deletions .github/workflows/merge-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fetch-depth: 0

- name: setup python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"

Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:

- name: code coverage report
if: ${{ github.event_name == 'pull_request' }}
uses: orgoro/coverage@32a2af98e56f47d958cf4c64b1f5e02161f2853e
uses: orgoro/coverage@c65003f41276ea33fe3a3a5d53df8b340462e8fa
with:
coverageFile: reports/coverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/merge-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
find . -type f | xargs chmod g+w

- name: setup python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
git merge --ff-only "${{ github.event.pull_request.head.sha }}"

- name: setup python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
git merge --ff-only "${{ github.event.pull_request.head.sha }}"

- name: setup python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"

Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:

- name: code coverage report
if: ${{ github.event_name == 'pull_request' }}
uses: orgoro/coverage@32a2af98e56f47d958cf4c64b1f5e02161f2853e
uses: orgoro/coverage@c65003f41276ea33fe3a3a5d53df8b340462e8fa
with:
coverageFile: reports/coverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -211,7 +211,7 @@ jobs:
git merge --ff-only "${{ github.event.pull_request.head.sha }}"

- name: setup python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"

Expand Down Expand Up @@ -296,7 +296,7 @@ jobs:
git merge --ff-only "${{ github.event.pull_request.head.sha }}"

- name: setup python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:

mesh_sandbox:
build:
context: https://github.com/NHSDigital/mesh-sandbox.git#refs/tags/v1.0.4
context: https://github.com/NHSDigital/mesh-sandbox.git#refs/tags/v1.0.13
ports:
- "8701:443"
deploy:
Expand Down
25 changes: 21 additions & 4 deletions mesh_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def _get_version(*names: str) -> str:
DEP_CA_CERT = os.path.join(_PACKAGE_DIR, "nhs-dep-ca-bundle.pem")
LIVE_CA_CERT = os.path.join(_PACKAGE_DIR, "nhs-live-ca-bundle.pem")

DEFAULT_MEDIA_TYPE = "application/octet-stream"


_OPTIONAL_HEADERS: Dict[str, str] = {
"workflow_id": "Mex-WorkflowID",
Expand All @@ -82,7 +84,7 @@ def _get_version(*names: str) -> str:
"compressed": "Mex-Content-Compressed",
"checksum": "Mex-Content-Checksum",
"partner_id": "Mex-PartnerID",
"content_type": "Content-Type",
"content_type": "Mex-Content-Type",
}


Expand Down Expand Up @@ -573,18 +575,22 @@ def retrieve_message_chunk(self, message_id: str, chunk_num: int) -> Response:
def _headers_for_chunk(
recipient: str, chunk_num: int, total_chunks: int, compress: bool, **kwargs
) -> Dict[str, str]:
content_type = kwargs.get("content_type", "application/octet-stream")
if chunk_num > 1:
headers = {
"Content-Type": content_type,
"Content-Type": DEFAULT_MEDIA_TYPE,
"Mex-Chunk-Range": f"{chunk_num}:{total_chunks}",
}
if compress:
headers["Content-Encoding"] = "gzip"
return headers

content_type = kwargs.get("content_type")
media_type = DEFAULT_MEDIA_TYPE
if content_type and total_chunks == 1:
media_type = content_type

headers = {
"Content-Type": content_type,
"Content-Type": media_type,
"Mex-Chunk-Range": f"{chunk_num}:{total_chunks}",
"Mex-To": recipient,
}
Expand All @@ -598,6 +604,10 @@ def _headers_for_chunk(
optional_args = ", ".join(["recipient", "data", *list(_OPTIONAL_HEADERS.keys())])
raise TypeError(f"Unrecognised keyword argument '{key}'. optional arguments are: {optional_args}")

if headers["Content-Type"] == headers.get("Mex-Content-Type"):
# don't send both if they're the same
headers.pop("Mex-Content-Type")

if compress:
headers["Content-Encoding"] = "gzip"

Expand Down Expand Up @@ -705,6 +715,7 @@ def send_message(
checksum
recipient
partner_id
content_type

Args:
recipient: mailbox id to send to
Expand Down Expand Up @@ -935,6 +946,7 @@ def __init__(self, msg_id: str, response, client):
self._mex_headers: Dict[str, Any] = {}

headers = response.headers

for header, header_value in headers.items():
lkey = header.lower()
if lkey.startswith("mex-"):
Expand All @@ -945,9 +957,14 @@ def __init__(self, msg_id: str, response, client):
if attribute in _BOOLEAN_HEADERS:
header_value = header_value or "N"
header_value = header_value.upper() in ["Y", "TRUE"]

setattr(self, attribute, header_value)
chunk, chunk_count = map(int, headers.get("Mex-Chunk-Range", "1:1").split(":"))

if not hasattr(self, "content_type") or not self.content_type: # type: ignore[has-type]
# try and get content_type from Mex-Content-Type first, but fallback to request content type if not set

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment relevant here? We're just setting whatever was decided in _headers_for_chunk()

setattr(self, "content_type", headers.get("Content-Type")) # noqa: B010

def maybe_decompress(resp):
return GzipDecompressStream(resp.raw) if resp.headers.get("Content-Encoding") == "gzip" else resp.raw

Expand Down
86 changes: 43 additions & 43 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading