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

Get mime fallback #2340

Merged
merged 14 commits into from
Mar 24, 2023
Merged

Get mime fallback #2340

merged 14 commits into from
Mar 24, 2023

Conversation

derkan
Copy link
Contributor

@derkan derkan commented Feb 21, 2023

Description

With current filesystem middleware, we don't let user to set custom content-type for a new extension when called from here. Becuse fiber's getMIME function uses statically defined mime types which cannot be changed.

This is needed when serving SPA project from emdedded filesystem where custom contet-types are needed. (i.e.sveltekit *.mjs file)

Fixes:

Allows fallback to golang's mime package for content-type detection. Because, go's default mime package allows setting custom mime types.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • For new functionalities I follow the inspiration of the express js framework and built them similar in usage
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation - https:/gofiber/docs for https://docs.gofiber.io/
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • If new dependencies exist, I have checked that they are really necessary and agreed with the maintainers/community (we want to have as few dependencies as possible)
  • I tried to make my code as fast as possible with as few allocations as possible
  • For new code I have written benchmarks so that they can be analyzed and improved

@welcome
Copy link

welcome bot commented Feb 21, 2023

Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@gaby
Copy link
Member

gaby commented Feb 22, 2023

@derkan Some small errors showing up in the tests/lint

@gaby
Copy link
Member

gaby commented Feb 22, 2023

@derkan Are the tests passing locally for you?

Copy link
Member

@ReneWerner87 ReneWerner87 left a comment

Choose a reason for hiding this comment

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

please check the failed tests

@derkan
Copy link
Contributor Author

derkan commented Feb 23, 2023

@derkan Are the tests passing locally for you?

yes

@derkan
Copy link
Contributor Author

derkan commented Feb 23, 2023

problem is with go.1.16.

For the following code:

package main

import (
	"fmt"
	"mime"
)

func main() {
	fmt.Println("result:", mime.TypeByExtension(".text"))
}
  • go.1.19 and go.1.20 this prints:
result: 
  • go.1.16 prints:
result: text/plain; charset=utf-8

And because of this, Test_Ctx_Accepts fails for go.1.16 at line:

utils.AssertEqual(t, "json", c.Accepts("json", "text"))

utils/http.go Outdated Show resolved Hide resolved
utils/http_test.go Outdated Show resolved Hide resolved
@ReneWerner87
Copy link
Member

https://expressjs.com/en/5x/api.html#req.accepts
image

we need a solution for this case
@derkan any ideas?

@derkan
Copy link
Contributor Author

derkan commented Mar 6, 2023

@ReneWerner87 a wrapper function(for making variadic - array type for mime names) around mime.ParseMediaType(...) can be enough? Playground

@ReneWerner87
Copy link
Member

@gaby @leonklingele @efectn any ideas or opinions ?

@gaby
Copy link
Member

gaby commented Mar 15, 2023

@gaby @leonklingele @efectn any ideas or opinions ?

It's a nice feature to add. I'm confused as to why the tests dont' pass for go 1.16 though.

May be worth making sure our unit-tests match the expected results as shown in https://expressjs.com/en/5x/api.html#req.accepts

brice-v added a commit to brice-v/blue that referenced this pull request Mar 19, 2023
…http.static

Note: I patched the mime-type code in gofiber's utils
to support mjs but a better
fix will
hopefully be available once gofiber/fiber#2340
is merged in.

For now every time I run `go mod vendor` I will have to update that file
back to my patched version
Copy link
Member

@leonklingele leonklingele left a comment

Choose a reason for hiding this comment

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

lgtm! 🚀

@gaby
Copy link
Member

gaby commented Mar 24, 2023

@derkan Can you update your branch with the latest changes in master. Trying to see if tests will pass.

@gaby
Copy link
Member

gaby commented Mar 24, 2023

CI is passing now!

@leonklingele
Copy link
Member

leonklingele commented Mar 24, 2023 via email

@ReneWerner87
Copy link
Member

i have made a sync with the upstream, otherwise you don't see the real changes because of all the copies(144 files) of the changes from the masters

@ReneWerner87 ReneWerner87 merged commit 547db83 into gofiber:master Mar 24, 2023
@welcome
Copy link

welcome bot commented Mar 24, 2023

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@derkan
Copy link
Contributor Author

derkan commented Mar 24, 2023

Thank you all! 💯

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

Successfully merging this pull request may close these issues.

5 participants