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

MimeDB.scala which is the mapping of file extension to Media Type should be auto-generated. #934

Closed
ashprakasan opened this issue Feb 1, 2022 · 7 comments
Labels

Comments

@ashprakasan
Copy link
Contributor

ashprakasan commented Feb 1, 2022

What is not easy to do right now?
#889 introduces a file - MimeDB.scala which is the mapping of file extension to Media Type. It should be auto-generated.

If a new Media-Type is added to master Mime db at https://cdn.jsdelivr.net/gh/jshttp/mime-db@master/db.json, it will have to be added manually to the zio-http codebase.

Describe the solution you'd like
There should be a way to either (1) automatically generate 'MimeDB.scala' from https://cdn.jsdelivr.net/gh/jshttp/mime-db@master/db.json` or (2) detection and addition of Content-Type header should be possible by directly using the mappings at https://cdn.jsdelivr.net/gh/jshttp/mime-db@master/db.json

Why is it important?
Future maintenance overhead will be high if this is not done.

Additional context
A few options for generating MimeDB.scala are -

As I understand, there are a few different options for auto-generating MimeDB.scala

  1. Generating code using string templates (Twirl).

    Pros : This seems to have the easiest learning curve of all the approaches.
    Twirl works very well with scala. The syntax is scala-ish
    Code is easy to read and understand.

    Cons : Can produce code that doesn't compile.

  2. Generating code from an abstract syntax tree (treehugger).

    Pros : Uncompilable code cannot be generated.
    Uses scala syntax.

    Cons : Steep learning curve. Will take me some time to do this.
    Not much IDE support.
    Code looks complex, reader might take some time to understand what is happening.

  3. Building an abstract syntax tree and sending it directly to the compiler (Scala macros).

    Pros : Directly passes bytecode of AST to next phase of compilation without generating .scala file
    Syntactically invalid code will not be generated.

    Cons : Steep learning curve. Will take me some time to complete this.
    Not much IDE support.
    Code can be complex. Reader needs to know macros to understand what is happening.

  4. Skip generating case classes entirely, by directly parsing json into a Map.

    Concern : There’s a 4kb limit on the size of a map in jvm afaik, so the Map will have to be split. Also, handling all edge-cases
    might get complicated.

@ashprakasan ashprakasan added the maintenance Chore or Maintenance tasks label Feb 1, 2022
@ashprakasan ashprakasan changed the title [#889](https://github.com/dream11/zio-http/pull/899) introduces a file - MimeDB.scala which is the mapping of file extension to Media Type. It should be auto-generated. MimeDB.scala which is the mapping of file extension to Media Type should be auto-generated. Feb 1, 2022
@ShrutiVerma97 ShrutiVerma97 reopened this Apr 8, 2022
@jdegoes
Copy link
Member

jdegoes commented Jun 5, 2024

/bounty $500

For a clean solution that requires no third-party dependencies and is easy to update.

Copy link

algora-pbc bot commented Jun 5, 2024

## 💎 $500 bounty • ZIO

### Steps to solve:
1. Start working: Comment /attempt #934 with your implementation plan
2. Submit work: Create a pull request including /claim #934 in the PR body to claim the bounty
3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

### Additional opportunities:
* 🔴 Livestream on Algora TV while solving this bounty & earn $200 upon merge! Make sure to have your camera and microphone on. Comment /livestream once live

Thank you for contributing to zio/zio-http!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟡 @kitlangton Jun 6, 2024, 5:55:30 PM #2918

@kitlangton
Copy link
Member

kitlangton commented Jun 6, 2024

/attempt #934
🥳

Algora profile Completed bounties Tech Active attempts Options
@kitlangton 1 ZIO bounty
Scala, Ruby,
Haskell & more
Cancel attempt

Copy link

algora-pbc bot commented Jun 13, 2024

@kitlangton: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏

@kyri-petrou
Copy link
Collaborator

@kitlangton just wanted to check-in with you if you're still working or planning to work on this issue. I'm also happy to collaborate on it if you like

Copy link

algora-pbc bot commented Jun 18, 2024

💡 @kitlangton submitted a pull request that claims the bounty. You can visit your bounty board to reward.

Copy link

algora-pbc bot commented Jun 19, 2024

🎉🎈 @kitlangton has been awarded $500! 🎈🎊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants