Last active
April 2, 2025 20:39
-
-
Save stephenlb/b6cadfd7c19964d6ccfc to your computer and use it in GitHub Desktop.
PubNub POST Gzip Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var http = require("http"); | |
| var zlib = require("zlib"); | |
| exports.publish = function(msg) { | |
| var req = http.request({ | |
| "host" : "pubsub.pubnub.com", | |
| "method" : "POST", | |
| "path" : "/publish/demo/demo/0/my_channel/0", | |
| "headers" : { | |
| "Content-Encoding" : "gzip", | |
| "Content-Type" : "application/json; charset=UTF-8", | |
| }, | |
| }, function (res) { | |
| var body = ""; | |
| res.on("data", function (chunk) { | |
| body += chunk; | |
| }); | |
| res.on("end", function () { | |
| console.log(body) | |
| }) | |
| }); | |
| req.on("error", function (e) { | |
| console.error("ERROR:", e.message); | |
| }); | |
| zlib.gzip(msg, function (error, result) { | |
| console.log("data:", result); | |
| req.write(result); | |
| req.end(); | |
| }); | |
| }; | |
| exports.publish('{"hello":["world",123,null]}'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | |
| ## PubNub POST GZIP Example | |
| ## -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | |
| echo '{"hello":["world",123,null]}' | gzip -c9 | \ | |
| curl \ | |
| -H "Content-Encoding: gzip" \ | |
| --data-binary @- \ | |
| 'http://pubsub.pubnub.com/publish/demo/demo/0/my_channel/0' | |
| echo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import http.client | |
| import zlib | |
| def publish(msg): | |
| req = http.client.HTTPConnection("pubsub.pubnub.com") | |
| req.request("POST", "/publish/demo/demo/0/my_channel/0", | |
| headers={"Content-Encoding": "gzip", | |
| "Content-Type": "application/json; charset=UTF-8"}, | |
| body=zlib.compress(msg.encode())) | |
| res = req.getresponse() | |
| body = res.read() | |
| print(body) | |
| publish('{"hello":["world",123,null]}') |
Author
Large Message POST
MSG=`LC_CTYPE=C tr -dc A-Za-z0-9 < /dev/urandom | fold -w 32700 | head -n 1`; \
echo "{\"msg\":\"${MSG}\"}" | \
curl -X POST --data @- 'https://pubsub.pubnub.com/publish/demo/demo/0/atari/0'; echoHTTP/2
MSG=`LC_CTYPE=C tr -dc A-Za-z0-9 < /dev/urandom | fold -w 32600 | head -n 1`; \
echo "{\"msg\":\"${MSG}\"}" | \
curl --http2 -X POST --resolve pubsub.pubnub.com:443:$(dig +short balancer-bronze-blue1.aws-pdx-1.ps.pn) --data @- 'https://pubsub.pubnub.com/publish/demo-36/demo-36/0/atari/0'; echo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.