Last active
December 15, 2022 21:19
-
-
Save stephenlb/b6cadfd7c19964d6ccfc to your computer and use it in GitHub Desktop.
PubNub POST Gzip Examples
This file contains 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 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 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]}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Large Message POST
HTTP/2