-
Notifications
You must be signed in to change notification settings - Fork 52
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
Custom HTTP Headers in Network Requests #132
Comments
Could you please give me more info about your pains or requests? |
Essentially let's say you have a pdf link that needs a auth token to enable access for the client device. I wasn't able to find a way to pass headers to the http request. Current Setup: Get the file from cache (download if not available already): Future<Either<ApiFailure, String>> getFilePath(String url) async {
try {
final credentials = await _authController.getUserCredentials();
final headers = credentials.authHeader;
final file = await _cacheManager.getSingleFile(
url,
headers: headers,
);
return right(file.path);
} catch (e) {
return left(ApiFailure.platform(LocaleKeys.standardErrorMessage.tr()));
}
}
Pass the path to the cached file in the PdfViewer return PdfViewer.file(
path, Ideal Setup would be to pass the headers to the widget itself (or having a custom client option that can make authenticated requests). Here the headers would have a bearer token that allows the client to access the file: PdfViewer.uri(
uri,
headers: {
'Authorization': 'Bearer <token>'
.... Maybe I am missing something and this feature already exists. I would love some guidance if that's the case. |
1.0.57 contains the fix above. |
Hey, sorry for the delayed response. I just tried to test but there is no way to pass the headers to the PdfDocument.openUri function from the widget. I went through the code and adding links to places where headers parameter would be needed below so that we can pass it from the widget. Thank you for all your help so far! pdfrx/lib/src/widgets/pdf_viewer.dart Line 103 in 5717726
pdfrx/lib/src/pdf_document_ref.dart Line 123 in 5717726
pdfrx/lib/src/pdf_document_ref.dart Line 144 in 5717726
pdfrx/lib/src/pdf_document_ref.dart Line 154 in 5717726
|
@espresso3389 I tested the latest release and it works. Thanks! |
We have been trying to figure out a way to use the PdfViewer.uri widget with a link that requires authenticated headers. The current setup we have uses a separate cache mechanism to download the file and then pass it on to the PdfViewer widget. Being able to pass the headers directly to the widget would be optimal in terms of caching and performance. Any insight on this would be appreciated. I would also be willing to work on a PR for this if you're open to it!
The text was updated successfully, but these errors were encountered: