Skip to content

feat: add overrideHost/Port/Scheme to presigned URL methods#111

Open
hammadparveez wants to merge 2 commits intoxtyxtyx:masterfrom
hammadparveez:feat/presigned-url-host-override
Open

feat: add overrideHost/Port/Scheme to presigned URL methods#111
hammadparveez wants to merge 2 commits intoxtyxtyx:masterfrom
hammadparveez:feat/presigned-url-host-override

Conversation

@hammadparveez
Copy link

Summary

Closes #101

In multi-network setups the MinIO client connects to an internal endpoint (e.g. http://internal-minio:9000), but presigned URLs distributed to external users must point to the public-facing address. Previously there was no way to customise the host/port/scheme of a presigned URL without instantiating a separate Minio client.

This PR adds three optional named parameters to presignedUrl(), presignedGetObject(), and presignedPutObject():

Parameter Type Description
overrideHost String? Replace the host in the presigned URL
overridePort int? Replace the port in the presigned URL
overrideScheme String? Replace the scheme (http/https)

All three are independent and optional — omitting one keeps the value from the client configuration. When any override is present, both the URL and the host header are updated before signing, so the resulting URL is fully valid for the external endpoint.

Usage example

final minio = Minio(
  endPoint: 'internal-minio.corp',
  port: 9000,
  useSSL: false,
  accessKey: '...',
  secretKey: '...',
);

// Generate a URL accessible from the public internet
final url = await minio.presignedGetObject(
  'my-bucket',
  'my-object.jpg',
  overrideHost: 'storage.example.com',
  overridePort: 443,
  overrideScheme: 'https',
);

Changes

  • lib/src/minio.dart — added parameters to presignedUrl, presignedGetObject, presignedPutObject
  • test/minio_presigned_url_test.dart — 6 new unit tests covering each override param and combined usage

Test plan

  • All existing presigned URL tests pass
  • New tests verify overrideHost, overridePort, overrideScheme individually and combined for both GET and PUT
  • Manual test: generate a presigned URL with overrides and verify it resolves via the public endpoint

hammadparveez and others added 2 commits February 24, 2026 18:57
Replace int.parse with int.tryParse when reading the content-length
response header in statObject. The header is not guaranteed to be
present; the null-check operator caused an unhandled crash. Using
tryParse with a null-coalescing fallback returns null gracefully,
which matches the already-nullable int? size field on StatObjectResult.

Fixes xtyxtyx#108

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
)

In multi-network architectures the MinIO client connects to an
internal endpoint, but presigned URLs distributed to external clients
must use the public-facing host, port, and/or scheme. Without these
overrides a separate Minio instance would have to be created just for
URL generation.

Add three optional named parameters to presignedUrl(), presignedGetObject(),
and presignedPutObject():
  - overrideHost  (String?)
  - overridePort  (int?)
  - overrideScheme (String?)

When any override is provided the request URL and its host header are
replaced before signing, so the resulting presigned URL is valid for
the external endpoint.

All existing tests continue to pass. New tests verify that each
override parameter (and all three together) are reflected in the
generated URL for both GET and PUT methods.

Closes xtyxtyx#101
Copilot AI review requested due to automatic review settings February 24, 2026 19:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds the ability to override the host/port/scheme used when generating presigned URLs so that a client can talk to an internal MinIO endpoint while distributing externally-valid presigned URLs.

Changes:

  • Add optional overrideHost, overridePort, and overrideScheme named parameters to presignedUrl(), presignedGetObject(), and presignedPutObject().
  • Apply URL + Host header overrides prior to SigV4 presigning.
  • Extend presigned URL unit tests to assert URL components reflect overrides.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lib/src/minio.dart Adds override parameters and rewrites the request URL/host header before calling SigV4 presign logic.
test/minio_presigned_url_test.dart Adds tests asserting the generated presigned URL reflects override host/port/scheme.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Successfully merging this pull request may close these issues.

Allow Customization of port, host, and scheme in presigned Functions for Enhanced Security

2 participants