Skip to content

Conversation

AndreasLymalmMTM
Copy link

@AndreasLymalmMTM AndreasLymalmMTM commented Sep 8, 2025

This PR should solve #22.

Functionality

This will set custom default HTTP headers for fetching all future publication resources. Also applies for resources for already opened publications.

Usage

final headers = {
  'Authorization': 'Bearer $accessToken',
};
await _flutterReadium.setCustomHeaders(headers);

Implementation

  • Created a new public function setCustomHeaders for flutter_readium.
  • Implementation on Android:
    • Stores the headers in a defaultHttpHeaders variable, which keeps its value across requests. When setting new headers, the same object reference for defaultHttpHeaders is kept, but is cleared of previous headers and filled with new ones.
    • Add an interception for the DefaultHttpClient when HTTP requests are made, where the defaultHttpHeaders are added.
  • Implementation on iOS:
    • Draft code, constructed similar to Android implementation.

Limitations

  • I didn't put headers on the existing openPublication function, because there wasn't a straight forward way to connect headers to specific publications, as publication ID isn't present at the time of HTTP requests. (Correct me if I'm wrong.)
  • Further implementation is needed for streaming resources from a publication. The created DefaultHttpClient should be used.

Testing

Has been tested on Android for these scenarios:

  • Setting headers once and making sure they are used when opening publications from URLs.

Note!

The iOS draft code needs to be looked over and tested.

@AndreasLymalmMTM AndreasLymalmMTM changed the title Feat/iss#22 additional headers feat: iss#22 additional headers Sep 9, 2025
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.

1 participant