Comments (3)
It appears that this is supported but MethodOverride only handles query parameters, however, while testing it seems that mkEnv doesn't handle encoded parameters from other StdMethod types than POST:
mkEnv :: StdMethod -> Request -> [Param] -> ResourceT IO ActionEnv
mkEnv method req captures = do
b <- BL.fromChunks <$> lazyConsume (requestBody req)
let parameters = captures ++ formparams ++ queryparams
formparams = case (method, lookup "Content-Type" [(CI.mk k, CI.mk v) | (k,v) <- requestHeaders req]) of
(POST, Just "application/x-www-form-urlencoded") -> parseEncodedParams $ mconcat $ BL.toChunks b
_ -> []
queryparams = parseEncodedParams $ rawQueryString req
return $ Env req parameters b
I'm not sure of the best way to generalize this, but people will probably want to be able to send parameters through the usual means. As a test I used a wildcard to capture all form-encoded parameters in mkEnv and this appears to work:
let parameters = captures ++ formparams ++ queryparams
formparams = case (method, lookup "Content-Type" [(CI.mk k, CI.mk v) | (k,v) <- requestHeaders req]) of
(_, Just "application/x-www-form-urlencoded") -> parseEncodedParams $ mconcat $ BL.toChunks b
_ -> []
I have not tested if this breaks existing functionality at this point.
from scotty.
Yes, MethodOverride only works with query parameters, so your html would need to be:
<form method="POST" action="/update?_method=PUT">
<input type="text" name="nickname" />
<input type="submit" />
</form>
Unfortunately, this is someone else's package, but I'm sure they would accept a patch if you found a clean way to look for "_method" in the form parameters.
As for mkEnv: yes this is very incomplete. There are several ways to encode form data, especially once you get to files and multipart data. I've only implemented the most basic method here because that is all I've needed so far. ;-)
Ideally, I'd rather form data get parsed in middleware, and attached to the request object on the way in. The WAI Request object has a Vault, which is probably where we'd store this. Then mkEnv could just look there.
I might take a crack at this later tonight, depending on how much else I get done today. :-P
from scotty.
Thanks Andrew.
I agree that this would be best handled with middleware. It should probably be included in wai-extra, then as you say, mkEnv can just pull the values out of the vault. I've begun adding a middleware to wai-extra that will parse application/x-www-form-urlencoded data similar to how Scotty does, however, I'm not experienced with the other encodings you mentioned.
What should I be looking out for? Are there any existing libraries I can use that you know of?
from scotty.
Related Issues (20)
- Is MonadReader ActionEnv (ActionT m) a good idea? HOT 1
- The name captureParam is a bit strange HOT 1
- doesn't compile against ghc 9.6.3 seems to need a version bump HOT 4
- Not able to rewrite the query string using Network.Wai.Middleware.Rewrite HOT 5
- [RFC] OpenAPI interop
- Expose Cookie via the main interface
- Add doctest
- Variable not in scope: pathParam In examples/basic.hs file HOT 3
- Establish API deprecation and cleanup policy
- SQLite module
- Accept text-2.1 HOT 1
- Update README with Stackage badges
- Undocumented change to the `File` type definition HOT 1
- Dependency upper bounds HOT 1
- Exception information is lost HOT 7
- Update CI to new action
- Add changelog for #374 HOT 1
- warp-3.4 not accepted HOT 2
- Optional validation of header contents
- Don't export ParseRequestBodyOptions
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 scotty.