Giter VIP home page Giter VIP logo

proxy's Introduction

Spectacles Proxy

The Spectacles proxy is responsible for handling all of the data interactions with Discord.

  • Ratelimited REST calls to Discord
  • Caching REST responses
  • Caching ingested data from the gateway

Usage

The proxy communicates with other services using the Spectacles spec over Redis.

The proxy can be configured with the following options. This file must be called proxy.toml and exist in the CWD. Alternatively, specify the values in the environment variables named adjacently. The following example contains the default values.

timeout = "" # TIMEOUT

[broker]
group = "proxy" # BROKER_GROUP
event = "REQUEST" # BROKER_EVENT

[redis]
url = "localhost:6379" # REDIS_URL
pool_size = 32 # REDIS_POOL_SIZE

[discord]
api_version = 10 # DISCORD_API_VERSION

[metrics]
# addr = "0.0.0.0:3000" # METRICS_ADDR
# path = "metrics" # METRICS_PATH

Timeout

The timeout is a human-readable duration (e.g. 2min). It applies for the entire duration of the request, including time paused for ratelimiting. Once the timeout occurs, the proxy will attempt to stop the request; however, it's possible for the data to be sent to Discord and the timeout to occur during the response, meaning that your client will receive the error but the request will have succeeded. This is done to protect against indefinitely hung requests in case Discord doesn't respond.

Request Format

Requests can be made by publishing on the specified event to the specified group. The data must be serialized in MessagePack format.

{
	"method": "GET",
	"path": "/users/1234",
	"query": {
		"foo": "bar"
	},
	"body": [],
	"headers": {
		"def": "uvw"
	}
}

query, body, and headers are optional. Body must be binary data.

Response Format

The response is returned on the callback queue in the following MessagePack format.

{
	"status": 0,
	"body": ...
}

Response Status

Status Description
0 Success
1 Unknown error
2 Invalid request format (non-JSON)
3 Invalid URL path
4 Invalid URL query
5 Invalid HTTP method
6 Invalid HTTP headers
7 Request failure
8 Request timeout

Response Body

For a successful call (status 0), the body will be an object representing the HTTP response:

{
	"status": 200,
	"headers": {
		"foo": "bar"
	},
	"url": "https://discord.com/api/v6/users/4567",
	"body": []
}

url represents the full, final URL of the request. body is the binary response body from the server.

For an unsuccessful status code (non-zero status), the body will be a string describing the error.

proxy's People

Contributors

fyko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

proxy's Issues

Add cancellation control

Requests are currently not cancelable. There should be several ways to cancel a request:

  • Per-request timeout
  • Global timeout configuration
  • Process exit (incomplete requests should be re-queued in this scenario)
  • Incoming event ("CANCEL" by default?) from a client based on IPC callback key

Add data caching

Add caching so each request doesn't necessarily result in a REST call to Discord. This will involve several things:

  • Redis(?) checks for each request
  • Direct ingest from the gateway
  • Cache bypass/override options

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.