Comments (6)
Both Request
and Response
require a ReadableStreamInterface
object because the stream needs to be readable at a minimum in order for the object to be useful. MessageInterface::getBody()
returns a ReadableStreamInterface
object for this same reason. Server
reads the stream from the Response
object and pipes it to the client socket stream.
Yes, often a DuplexStreamInterface
object is provided so the stream may be written to by the application, but writing to the stream isn't strictly necessary. Perhaps you'd provide a read-only file stream (which is a component that still needs to be written) as the stream in a Response
object.
Also consider a Response
object in the client context (which is also a part of this library). In this case the response object would be read by the application code.
Is there a problem you've run into when trying to use these objects? Maybe I could help. Sorry there isn't documentation yet. My time has been occupied by other work.
from http.
No, I don't have any problems, it's just that I don't like how it currently works for handling server-side requests. Say we have a middleware that takes a requests, fills response with data and then sends it back to client. What would be the best, elegant way to ensure that response is writable, without adding IF instruction within middleware itself?
I fully agree with what you wrote above, but how should we handle my use case?
from http.
My understanding is that such middleware would return a new response object with a different stream of it's choosing. Since the messages are immutable, middleware really should be returning a new instance rather than writing to the stream of another object. Does that make sense, am I understanding middleware correctly?
from http.
Yeah, it makes sense. Actually, after getting into coding, I had to change my approach, so this is not a problem anymore.
from http.
I would be interested in seeing what you're doing. I'm debating if I should switch up some things about Server
, so I'd like to have some more input. I wanted to get this package relatively stable so I could build the WebSocket package on top of it soon.
from http.
I'm mostly playing around now ;-)
It is related to Psr7Bridge, I'm trying to build a stack of PSR-7 middlewares that can be easily connected to Icicle.
At first I wanted to convert Icicle's request into PSR7 message, pass it along, take the response, convert it, and send back to user. When working on it, I thought that Response body should always be writable, so I filled this ticket :)
But, it was a dead end, it didn't work as expected, complicated things and looked ugly. So now I'm going to skip converting response in favour of writting emitter that takes PSR-7 message and sends it via Icicle.
After getting to something interesting I'll publish my results to Gist or a repo.
What changes are you considering? If you want my opinion, open an issue and @-ping me :-)
from http.
Related Issues (14)
- How to process with "Connection: upgrade" requests HOT 9
- PSR-7 Compatibility? HOT 9
- PSR-7? HOT 3
- Memory leak? HOT 6
- Url parse problem HOT 2
- encodeValue does not encode "+" to "%2B"
- Connection: keep-alive [feature request] HOT 2
- Web and socks proxy [feature request] HOT 2
- How to retrieve POST data?
- Http server error: uncaught exception when creating response to a request
- Fatal error running the example in the docs
- HTTP 2 support HOT 4
- How do I stream a response using chunked transfer encoding ?
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 http.