Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New versions without accepted pull requests with gzip requests #1038

Closed
gawsoftpl opened this issue Mar 11, 2023 · 3 comments
Closed

New versions without accepted pull requests with gzip requests #1038

gawsoftpl opened this issue Mar 11, 2023 · 3 comments

Comments

@gawsoftpl
Copy link
Contributor

Hi,
My pull requests was accepted #950 but in new versions I can't see gzip compress for incoming requests:

In master branch is: https://raw.githubusercontent.com/SeldonIO/MLServer/master/mlserver/rest/requests.py

from typing import Any
from gzip import decompress as gzip_decompress
from fastapi import Request as _Request

try:
    import orjson
except ImportError:
    orjson = None  # type: ignore


class Request(_Request):
    """
    Custom request class which uses `orjson` if present.
    Otherwise, it falls back to the standard FastAPI request.
    """

    async def body(self) -> bytes:
        if not hasattr(self, "_body"):
            body = await super().body()
            if "gzip" in self.headers.getlist("Content-Encoding"):
                body = gzip_decompress(body)
            self._body = body
        return self._body

    async def json(self) -> Any:
        if orjson is None:
            return await super().json()

        if not hasattr(self, "_json"):
            body = await self.body()
            self._json = orjson.loads(body)

        return self._json

in Version 1.24 requests.py have value:

from typing import Any

from fastapi import Request as _Request

try:
    import orjson
except ImportError:
    orjson = None  # type: ignore


class Request(_Request):
    """
    Custom request class which uses `orjson` if present.
    Otherwise, it falls back to the standard FastAPI request.
    """

    async def json(self) -> Any:
        if orjson is None:
            return await super().json()

        if not hasattr(self, "_json"):
            body = await self.body()
            self._json = orjson.loads(body)

        return self._json
@gawsoftpl
Copy link
Contributor Author

I see that there is multiple branches 1.2.x and 2.x.x
I will create pull requests for those branches

@gawsoftpl
Copy link
Contributor Author

Added pull requests for this #1041 #1040

@adriangonz
Copy link
Contributor

Hey @gawsoftpl ,

These branches are internal branches used to prepare releases. PRs should only be merged against master.

Since #950 was merged after the 1.2.x release was out, it will need to wait until the 1.3.x release. In the meantime, if you want to try it out, you should be able to use our dev releases (e.g. 1.3.0.dev3).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants