New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ephemeral-socket-service

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ephemeral-socket-service

Express middleware for an ephemeral socket service

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

Ephemeral Socket Service

This express middleware allows you to accept incoming HTTP POST requests that will be piped through to later HTTP GET requests.

Why would I want to?

The server acts as a file sharing service but the data is never stored on the server. Instead, the incoming HTTP POST is accepted and then stalled until the HTTP GET request is made. In order to know what URL to use for the HTTP GET request, we write a partial response to the HTTP POST but do not close the stream.

Usage

  1. Create an express server.
  2. Attach this middleware.
  3. Respond to events on middleware to create your service.

Here is how it might look:


# Create express server
express = require 'express'
app     = express()

# Initialize middleware
service = require('ephemeral-socket-service').attach(app)

# Respond to events
service.on 'socket:opened', (socket, socketId, query) ->
  socket.res.writeHead(200)
  socket.res.write("Ephemeral socket open with ID #{socketId}")

service.on 'socket:end', (socket, stats) ->
  socket.res?.write('\n\nUpload complete. Socket deleted.\n')
  socket.res?.end()

service.on 'socket:timeout', (socket) ->
  socket.res?.write('\n\nTimed out. No one requested your socket.\n')
  socket.res?.end()

service.on 'error:not-found', (req, res) ->
  res.status(404).send('Not found')

# Serve
app.set('port', 9000)
server = app.listen(app.get('port'), ->
  console.log('Listening on %s', server.address().port)
)

Options

EphemeralSocketService.attach() takes an option hash as its second argument. The available options are:

keydefaultdescription
ttl600Time (in seconds) that a socket may stay open before it times out
maxUploadBytes2^30 (1 GB)Set the max number of bytes allowed to be piped through a socket. HTTP POSTs will be rejected with a 413 status code if they exceed this limit
reservationsfalseAdds /reserve middleware to allow users to create an ephemeral socket before creating an HTTP POST. This is useful when scripting this service within a web browser as most don't support streaming HTTP POST responses.
requiredReferernullRECOMMENDED if you are using reservations. If defined with a string like "http://localhost:9000", this will restrict reservations to that specific referer.
ids{...}An object for creating the socket IDs. See ids.coffee

Keywords

FAQs

Package last updated on 02 Dec 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc