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

Change datatype of Content.length to long long #397

Merged
merged 4 commits into from
Jul 14, 2023
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0a9] - 2023-07-14

- Fixes bug #394, causing the `Content` max body size to be 2147483647
(C int max value). Reported and fixed by @thomafred

## [2.0a8] - 2023-07-02

- Add support for `StreamedContent` with specific content length; fixing
Expand Down
2 changes: 1 addition & 1 deletion blacksheep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
used types to reduce the verbosity of the imports statements.
"""
__author__ = "Roberto Prevato <[email protected]>"
__version__ = "2.0a8"
__version__ = "2.0a9"

from .contents import Content as Content
from .contents import FormContent as FormContent
Expand Down
2 changes: 1 addition & 1 deletion blacksheep/contents.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
cdef class Content:
cdef readonly bytes type
cdef readonly bytes body
cdef readonly int length
cdef readonly long long length


cdef class StreamedContent(Content):
Expand Down
2 changes: 1 addition & 1 deletion blacksheep/contents.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cdef class StreamedContent(Content):
self,
bytes content_type,
object data_provider,
int data_length = -1
long long data_length = -1
):
self.type = content_type
self.body = None
Expand Down
11 changes: 10 additions & 1 deletion tests/test_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import pytest

from blacksheep import JSONContent, Request, StreamedContent
from blacksheep import JSONContent, Request
from blacksheep.contents import (
FormPart,
HTMLContent,
MultiPartFormData,
StreamedContent,
TextContent,
parse_www_form,
write_www_form_urlencoded,
Expand Down Expand Up @@ -323,3 +324,11 @@ async def test_write_request_body_only(req: Request, expected_chunks: List[bytes
received_chunks.append(chunk)

assert received_chunks == expected_chunks


@pytest.mark.parametrize("size", [0, 2000, 2147483647, 9e18])
def test_content_size(size):
async def gen():
yield b""

StreamedContent(b"text/plain", gen, size)
Loading