-
Notifications
You must be signed in to change notification settings - Fork 70
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
Files in public directory being opened as UTF8 Strings #25
Comments
This issue isn't as simple as writing an else statement and returning a different response since responses must have a body of the following type: |
@califrench thanks. I believe there is solution for mime types management in Swift, we should not be very first facing this issue :) Please let me know if you will find something. |
@sauliusgrigaitis I realized that this was highlighting two different issues as I typed my explanation up. |
This adds support for the `mimeType()` function on `String?` types. The previous implementation allowed to pass nil values to the internal `MimeType(ext: String?) -> String` function but `.mimeType()` could never be called on a nil String because that was an extension on the `String` type. This allows us to do this ```swift let testString :String? = nil testString.mimeType() // -> "application/octet-stream" ``` Instead of this ```swift let testString : String? = nil (testString ?? "").mimeType() // -> "application/octet-stream" ``` Or worse ```swift let testString : String? = nil testString.extension?.mimeType ?? "application/octet-stream" // ->"application/octet-stream" ``` This new implementation is used in the router and fixes sauliusgrigaitis#25
This adds support for the `mimeType()` function on `String?` types. The previous implementation allowed to pass nil values to the internal `MimeType(ext: String?) -> String` function but `.mimeType()` could never be called on a nil String because that was an extension on the `String` type. This allows us to do this ```swift let testString :String? = nil testString.mimeType() // -> "application/octet-stream" ``` Instead of this ```swift let testString : String? = nil (testString ?? "").mimeType() // -> "application/octet-stream" ``` Or worse ```swift let testString : String? = nil testString.extension?.mimeType ?? "application/octet-stream" // ->"application/octet-stream" ``` This new implementation is used in the router and fixes sauliusgrigaitis#25 Forgot semicolon in Router Changed extension to ``extension`` Updated the Optional extension to allow any kind of optional. Thought it would be unsafe to force cast an Optional of a different type to a String? but turns out to work just fine Added safety to the optional extension. Casting a non nil Optional type of any other type than String would previously cause a crash. Oops, forgot parentheses Updated the Router to use optional chaining and removed the optional extension on MimeType Added a static test javascript file and updated the tests to check for the mime type served by the router for static files.
This is no longer an issue. |
This is a duplicate of #28 |
I'm trying to load images from the public directory but it seems from looking at the router code that anything loaded from the public directory needs to be source code—like css or js files.
We should be able to also load images and other assets from that directory. Also CSS files and JS files should return a different mimetype than
text/plain
.The text was updated successfully, but these errors were encountered: