Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
A Python package for setting HTTP headers on Amazon Web Services (AWS) S3 objects.
A Python package for setting HTTP headers on Amazon Web Services (AWS) S3 objects.
Header values are configured per-name extension, with an optional catch-all if the object does not match any rules.
Python 3.x is required.
Only Cache-Control
and Content-Type
headers are currently supported.
The headers to set are configured in a YAML file with a list of rules.
For example:
- header: Cache-Control
when:
- extension: .html
then: max-age=300, public
- extension: .css
then: max-age=604800, public
else: max-age=31536000, public
The result of this will be:
.html
object will receive a Cache-Control
header with value max-age=300, public
..css
object will receive a Cache-Control
header with value max-age=604800, public
.Cache-Control
header with value max-age=31536000, public
.The else
statement is optional. For example:
- header: Content-Type
when:
- extension: .woff2
then: font/woff2
The result of this will be:
.woff2
object will receive a Content-Type
header with value font/woff2
.Content-Type
header (or lackthereof) on all other objects will be unchanged.There's a sample file at sample-header-rules.yaml.
pip install s3headerize
python -m s3headerize --bucket <bucket to update>
--header-rules <path to rules file>
[--dry-run]
[--key-prefix <optional key prefix>]
[--log-level <optional log level>]
For example:
python -m s3headerize --header-rules ./headers-rules.yaml --bucket my-website
To run against a bucket:
from s3headerize import BucketHeaderizer
rules = [
{
'header': 'Cache-Control',
'when': [
{
'extension': '.html',
'then': 'max-age=300, public'
}
],
'else': 'max-age=31536000, public'
},
{
'header': 'Content-Type',
'when': [
{
'extension': '.woff2',
'then': 'font/woff2'
}
]
}
]
bucket_headerizer = BucketHeaderizer(header_rules=rules)
bucket_headerizer.update(bucket='my-website')
To run against specific keys:
from s3headerize import ObjectHeaderizer
rules = [
{
'header': 'Cache-Control',
'when': [
{
'extension': '.html',
'then': 'max-age=300, public'
}
],
'else': 'max-age=31536000, public'
},
{
'header': 'Content-Type',
'when': [
{
'extension': '.woff2',
'then': 'font/woff2'
}
]
}
]
object_headerizer = ObjectHeaderizer(bucket='my-website',
header_rules=rules,
key='index.html')
object_headerizer.update()
pip install -e .[dev]
python test.py
FAQs
A Python package for setting HTTP headers on Amazon Web Services (AWS) S3 objects.
We found that s3headerize demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.