Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Have you ever wanted to utilize Content-Encoding: chunked
in XHR, without waiting for the entire request to complete? With Streamable, you can!
HTTP/1.1 chunked encoding is a really useful feature of the protocol, however, its really disappointing that we cannot interact with it directly via XHR. Instead, we have to wait for the entire request/response cycle to be complete, before we can start interacting with the data thats coming to us over the wire!
Since we cannot rely on the HTTP protocol alone, we use a hybrid strategy that negotiates initially over HTTP at first, then coordinates chunked data transmission using asynchronous pipelines. Ideally, this is accomplished using WebSockets, but will feature detect as you would expect, thanks to socket.io. So rather than reinventing the HTTP protocol over sockets, we couple the two protocols together into a single API.
Streamable is designed to feel transparent. If you access a streamable REST endpoint without the Streamable client, native chunked encoding will happen in its place. You can also explicitly disable Streamable for a particular request by sending the x-streamable-bypass
request header. If streamable is bypassed, each message will be delimeted with \r\n
. This is also configurable by provided the x-streamable-delimiter
request header, providing the value you'd like to use instead.
install Streamable using npm:
npm install streamable
Streamable is implemented as an Express/Connect middleware, so its really simple to use. It assumes you've got both Socket.io and Express modules already included in your app.
// setup an express 3.x server
var express = require('express');
var app = express();
var server = require('http').createServer(app);
// setup a socket.io server and attach it to express
var io = require('socket.io').listen(server);
Once you've got that setup, its easy to setup Streamable, just pass in your socket.io server instance and the middleware is ready to go.
var streamable = require('streamable').streamable(io);
At this point, we just drop the Streamable middleware into our routes
app.get('/myAPI', streamable, function(req, res){
res.write('streaming…');
res.write('streaming…');
res.end();
});
The streamable API also allows you to send fatal and non-fatal errors via the res
object.
res.fatal(new Error('this will fire the onError event and close the response stream'));
res.error(new Error('this will fire the onError event and keep going'));
the write API also supports json
as a valid encoding, for convenience.
res.write(["here", "is", {some, "data"}], 'json');
The client side requires you to have jQuery (for XHR) and the socket.io client-side library. Make sure those are loaded before adding the Streamable client JavaScript module. Once its all loaded up, its really easy to start using.
<script type="text/javascript">
Streamable.get("/myAPI", {
onData : function(data) { console.log('data:' , data); },
onError : function(e) { console.log('error:', e); },
onEnd : function() { console.log('end'); }
});
</script>
the onData
call will happen n times--once per write. The onEnd
call is guaranteed to be called one time after all onData
and/or onError
events have fired. If you've passed multiple values to write on the server-side, you can expect them as arguments in the same order of your onData
event handler.
Copyright (C) 2012 Derek Perez derek@derekperez.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Super simple streaming responses for Connect/Express.
The npm package streamable receives a total of 3 weekly downloads. As such, streamable popularity was classified as not popular.
We found that streamable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.