Skip to content
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

BrookStaticFileBroker: extentions instead directories #7

Open
Al-Muhandis opened this issue May 14, 2019 · 2 comments
Open

BrookStaticFileBroker: extentions instead directories #7

Al-Muhandis opened this issue May 14, 2019 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@Al-Muhandis
Copy link
Contributor

Is it possible to BrookStaticFileBroker by file extensions rather than by directories as of now as well. At the same time, so that we can configure separately for such cache time.
Now I use this nginx, but do not always have the opportunity to use it

@Al-Muhandis Al-Muhandis added enhancement New feature or request question Further information is requested labels May 14, 2019
@silvioprog
Copy link
Member

Is it possible to BrookStaticFileBroker by file extensions rather than by directories as of now as well.

It uses TFPMimeTypes internally which provides GetMimeType(), so maybe it's possible.

At the same time, so that we can configure separately for such cache time.

If you want an already cached logic, you should use BrookMediaTypes.pas from Brook Tardigrade (lack examples, but I could send one soon). It caches the media types into a hash table and the item finding is done by a Jenkins hash function internally.

Also, it provides type detection which could be combined to compression feature also available on Brook, for example:

  FN := YourRequestedFileName;
  EX := ExtractFileExt(FN);
  CT := MIME.Types.Find(EX);
  if MIME.Types.IsText(CT) then
  begin
    // process the Accept-Encoding header to accept raw DEFLATE compression through
    // "ARes.Compressed := <your logic>" saving data transferring in ~93% or above
    ARes.Render(FN);
  end
  else
  begin
    if MatchText(EX, ['.html', '.css', '.js', '.xml', '.json']) then
    begin
      // process the Accept-Encoding header to accept Gzip compression through
      // "ARes.Compressed := <your logic>" saving data transferring in ~89% or above
    end;
    ARes.Download(FN);
  end;

Now I use this nginx, but do not always have the opportunity to use it

I've used the Nginx logic some time ago, but I left it after BrookMediaTypes came. If you want to use it too, you can reuse your already configured mime.types file from Nginx by enabling the TBrookMIME.Provider := 'Nginx'. There are another ways, for example, you can write your own provider (reading the media types from stream, file, string, list, database, register etc.) and register it like the ones here, so you can enable it through TBrookMIME.Provider := '<Your-awesome-provider>'. Or just left Brook to detect one for your system. (I'm on openSUSE and Brook reused the one available at /etc/mime.types; on Windows I've used the default provider and this mime.types copy)

@Al-Muhandis
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants