Skip to content

API

function bareasgi_static.add_static_file_provider

Summary

Add static file support.

bareasgi_static.add_static_file_provider(
app: Application,
source_folder: str,
*,
mount_point: str,
check_source_folder: bool,
index_filename: Optional[str]
) -> Any

Parameters

app: Application

The bareASGI application.

source_folder: str

Where to find the files to serve.

mount_point: str (optional)

Where the files should appear on the url. Defaults to '/'.

check_source_folder: bool (optional)

If True check the source folder exists. Defaults to True.

index_filename: Optional[str] (optional)

An optional index file name. Defaults to None.

Returns

Any:

class StaticFilesProvider

Summary

A static file provider.

bareasgi_static.StaticFilesProvider(
source_folder: str,
*,
path_variable: Optional[str],
check_source_folder: bool,
index_filename: Optional[str]
) -> None

Parameters

source_folder: str

Where to find the files to serve.

path_variable: Optional[str] (optional)

A path variable to capture the mount point. Defaults to None.

check_source_folder: bool (optional)

If True check the source folder exists. Defaults to True.

index_filename: Optional[str] (optional)

An optional index file name. Defaults to None.

async function bareasgi_static.file_response

Summary

A utility method to create a file response.

async bareasgi_static.file_response(
request: HttpRequest,
status: int,
path: str,
headers: Optional[Headers],
content_type: Optional[str],
filename: Optional[str],
check_modified: Optional[bool]
) -> HttpResponse

Parameters

request: HttpRequest

status: int

The HTTP status code.

path: str

The path to the file.

headers: Optional[Headers] (optional)

The headers. Defaults to None.

content_type: Optional[str] (optional)

The content type.. Defaults to None.

filename: Optional[str] (optional)

The filename. Defaults to None.

check_modified: Optional[bool] (optional)

If True check for modifications to the file. Defaults to False.

Returns

HttpResponse: The HTTP response

async generator function bareasgi_static.file_writer

Summary

Creates an async iterator to write a file.

async bareasgi_static.file_writer(
path: str,
chunk_size: int
) -> Content

Parameters

path: str

The path of the file to write.

chunk_size: int (optional)

The size of each block. Defaults to CHUNK_SIZE.

Yields

Content: An async iterator of bytes.