Git Product home page Git Product logo

http-reverse-connect's Introduction

http-reverse-connect

Tests about server-initiated-http calls

This is basically to allow us to do REST over outbound connections from the server, to satisfy the "only allow outbound connections" security model.

Currently the demo is between "client" and "aspnetcoreserver", where "client" is the Actual client, but acts as a server in the websocket setup.

In this demo the "client" starts a websocket server, and listens for incoming requests. The "server" then starts a client, establishing the outbound connection between them.

The connection is then used for the client to send a message to the server through a simple RPC interface, that is meant to mimic REST in time. The "server" then spins up an HttpClient and does a "regular" http call on localhost.

The plan is to mimic calling REST endpoints via websockets, and this is one way to get exactly the same behaviour. Another alternative could be to get the required controller via an IServiceProvider which is probably less overhead but might have some subtler issues.

After the REST request is finished, the result is "proxied" back over the websocket request to the client.

This isn't even close to being production-grade code, but it does demonstrate that REST over outbound connections can be performed.

Alternative architecture

Instead of needing to add something on the server, it's possible to add a websocket-proxy that establishes the connection, and just proxies it to REST-requests. The ws-proxy could then have a white-list of allowed endpoints to call.

See diagram below:

arch

An implementation of such a websocket-proxy server is in the branch "feature/rest-over-websockets"

Technically the "WS" server on the client-side could probably also be a standalone-server that proxied REST requests on the websocket connection, which then only maintained the websocket connections.

Having them as standalone services means higher overhead, but it also means that clients and servers don't need to care that their communication is going on via WS - to them it's just "regular" http calls.

Limitations

There's no retry ability currently. To try out the code you have to (in this order)

  • start the client (which starts a websocket server)
  • start the server (which starts the websocket client and establishes connection)

There's also no multiplexing or support for more than one websocket at a time.

Other approaches: We could potentially use HTTP2 SSE, like this. HTTP2 SSE https://medium.com/blogging-greymatter-io/server-sent-events-http-2-and-envoy-6927c70368bb

License: No license currently, do not use.

http-reverse-connect's People

Contributors

geewee avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.