resgateio/resgate

Allow WebSocket compression

Closed this issue · 1 comments

Story

Resgate should have an option to enable WebSocket message compression.

This would effectively counter the bloated message size when receiving resources with multiple models containing the same key names.

Example
A collection of reference to models could look like this:

{
  "result": {
    "models": {
      "notes.note.1": {
        "id": 1,
        "message": "One"
      },
      "notes.note.10": {
        "id": 10,
        "message": "Ten"
      },
      "notes.note.2": {
        "id": 2,
        "message": "Two"
      },
      "notes.note.3": {
        "id": 3,
        "message": "Three"
      },
      "notes.note.4": {
        "id": 4,
        "message": "Four"
      },
      "notes.note.5": {
        "id": 5,
        "message": "Five"
      },
      "notes.note.6": {
        "id": 6,
        "message": "Six"
      },
      "notes.note.7": {
        "id": 7,
        "message": "Seven"
      },
      "notes.note.8": {
        "id": 8,
        "message": "Eight"
      },
      "notes.note.9": {
        "id": 9,
        "message": "Nine"
      }
    },
    "collections": {
      "notes.notes": [
        {
          "rid": "notes.note.1"
        },
        {
          "rid": "notes.note.2"
        },
        {
          "rid": "notes.note.3"
        },
        {
          "rid": "notes.note.4"
        },
        {
          "rid": "notes.note.5"
        },
        {
          "rid": "notes.note.6"
        },
        {
          "rid": "notes.note.7"
        },
        {
          "rid": "notes.note.8"
        },
        {
          "rid": "notes.note.9"
        },
        {
          "rid": "notes.note.10"
        }
      ]
    }
  },
  "id": 1
}

Due to the repetitiveness of the data, gzip compression would reduce this from 704 bytes to 202 bytes.

Implementation

If enabled in the configuration, the Gorilla WebSocket updater should have the EnableCompression flag set to true.

Since the Gorilla WebSocket Compression feature is still flagged as Experimental, Resgate should have compression disabled by default.

An option should be added to the configuration file. Since http compression might later be added, the option name should clearly indicate it is for the WebSocket:

wsCompression (boolean)
Flag telling if WebSocket per message compression (RFC 7692) is enabled.
Example: false

Resolved in #106