Comments (6)
I made an example for the above approach: gist. As I mention there, there are a few disadvantages most notably the non-dynamic lookup ability and use of static
methods.
Love to hear your thoughts on it
from malloy.
This could now be done atop #17. With the Filter
concept a function like valid_request
could be introduced, which took in a header and just returned bool as to whether to accept that request. Alternatively it could be a more specialised accept_mimetype
which only takes in a string for the mimetype and returns bool.
One snag is that only router::add
currently allows passing a filter, so if we went that route it would need to be added to add_file_serving
and add_redirect
(potentially). So it might actually be better to define another concept that is an optional subset of Filter
and use that (for Filter accepts_mimetype
would be optional, add_file_serving
uses the subset where that is not optional).
Finally, a seperate but related issue, should mimetypes be strongly typed? (i.e. have a mime
object passed around instead of std::string
or whatever). I have some code for mimetype detection that uses a constexpr
array for the lookup and stores the index to the pair that has the extension + name in it. This has the advantage that it can be constructed from either the extension or name (and can be asked for either) and is the size of a uint16_t
(could be smaller with less recognised mimetypes). Problem with that is how to deal with unknown mimetypes.
Thoughts?
from malloy.
At this point I'd mainly like to note that this functionality is also relevant for responses, not just requests.
Personally I am very-pro providing strongly typed values for common MIME types. However, the user needs to be able to set any MIME-type as well (i.e. by just passing a string).
It should be fairly simple to provide the infrastructure to use built-in strongly typed MIME types for the standard types and as an option allow to just set a string value instead.
I also think that the list of pre-defined strongly typed MIME types should ideally be extendable by the user during compile time for registering non-standard, application specific MIME types while still being able to use them through the strongly-typed interface(s) after registration.
from malloy.
I was thinking it wouldn't make much sense for it to apply to the Filter
for responses since theres no overloading happening there. Not sure if thats what you meant.
I agree that the mimetype list needs to be extensible by the user. But having it as a global which is also extensible is a bad idea imo. One way around that would be template-based dependency injection like what beast::http::message
uses. That would allow us to define a basic set of common ones and have users define their own, while maintaing the lightweight nature. The type to inject could be specified in the Filter
(accepts_mimetype
would take in a mime<T>
)
from malloy.
I had a look at this - I think that's a pretty good start!
Cons: Its templated, meaning library code for it will also need to be templated in some way
I'm wondering how bad this is gonna be in practice. After all, malloy
is already heavily templated and underlying boost
even more so.
from malloy.
@0x00002a I'm currently revisiting this topic - are you up for a discussion?
from malloy.
Related Issues (20)
- Usage of start() HOT 9
- Client: SNI hostname on WSS connection
- HTTP: More centralized configuration
- Connection timeout configuration
- Cross-Platform Way to Get Root Certs From Store? HOT 4
- server::listener: provide method for catching binding errors
- HTML form: check for requires fields HOT 2
- HTTP server: Add cache control HOT 1
- HTML form: populate() potentially dangerous HOT 1
- Custom HTTP response generator
- controller i/o threads reservation
- Form parsing should honor Content-Type
- Deprecate HTML namespace
- Generator response types HOT 1
- CMake: Check Windows 11 implementation for get_WIN32_WINNT
- HTTP Client: Allow connection re-use
- Potential issue in session cookie handling
- HTTP: Improve cookie handling
- HTTP connection detector: Different logging styles
- Consider using Botan for host certificate store access HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from malloy.