Comments (6)
Yeah, I recall having thought about this before. It would make sense for readBody
to make a request state transition. The problem is streamBody
, which currently "leaks" the underlying Stream
. Maybe that operation could also transition to BodyRead
, but you'd be on your own in terms of safety.
from hyper.
Just sketching:
data HeadersRead
data BodyRead
-- | A middleware transitioning from one `Request` state to another.
type RequestStateTransition m req from to a =
forall res c.
Middleware
m
(Conn (req from) res c)
(Conn (req to) res c)
a
class Request (req :: Type -> Type) m where
getRequestData
:: forall state res c
. Middleware
m
(Conn (req state) res c)
(Conn (req state) res c)
RequestData
class Request req m <= BaseRequest req m
-- | A `ReadableBody` instance reads the complete request body as a
-- | value of type `b`. For streaming the request body, see the
-- | [StreamableBody](#streamablebody) class.
class (Request req m) <= ReadableBody req m b where
readBody
:: RequestStateTransition m req HeadersRead BodyRead b
from hyper.
Maybe the StreamableBody
method could take the streaming consumer function as an argument, and directly changing the state of the request to BodyRead
:
class (Request req m) <= StreamableBody req m stream | req -> stream where
streamBody :: (stream -> m Unit) -> RequestStateTransition m req HeadersRead BodyRead b
So you'd get access to the underlying stream only inside the supplied function.
from hyper.
I'd like to pick up this issue following the same approach I proposed in #86.
I think the HeadersRead
and BodyRead
should be renamed to HeadersReadable
and BodyReadable
. Both convey the idea that those aspects are "readable" in that current state. The final transition could be FullyRead
or something like that.
Just to clarify, but should there also be a type for reading the status line?
from hyper.
I think the HeadersRead and BodyRead should be renamed to HeadersReadable and BodyReadable. Both convey the idea that those aspects are "readable" in that current state. The final transition could be FullyRead or something like that.
IIRC (it was some time ago since I worked on this), the status line and headers are always read. The only state transition currently represented is not having read the body (HeadersRead
) and (BodyRead
). You could explicitly represent the prior states, too, but I'm not sure how useful it is for a user of Hyper. Only when implementing the underlying HTTP server would you care about reading status/headers (and I don't even know if the NodeJS HTTP API supports that level of control). Does that make sense?
from hyper.
Makes sense. I was thinking of parallels to the request state, so this came to mind.
from hyper.
Related Issues (20)
- Invalid query strings cause exceptions HOT 2
- Hyper app crashes on thrown exceptions HOT 4
- fileServer doesn't handle query strings HOT 1
- Adapter for express js middleware HOT 3
- Updated to purescript-aff-4.0.0
- Should we treat `+` as `%20` in uri query part? HOT 3
- Add hyper to package-sets HOT 3
- Numerous compiler warnings to address
- Documentation hosting HOT 2
- 0.9.0 release HOT 6
- [Info/Question] PureScript 0.12 HOT 6
- Define kind `ResponseState` and annoate `res` with kind `ResponseState -> Type`
- Unable to find a suitable version for purescript-typelevel-prelude HOT 2
- Redefine `IxMonadMiddleware` to mirror `MonadState` more HOT 1
- Remodel code via Indexed Capability Design Pattern?
- Review Travis integration
- Ability to close server
- git clone https://github.com/purescript-hyper is too slow
- Re-enable installation with PureScript 0.14 and Spago
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 hyper.