MCPcopy
hub / github.com/google/tamperchrome / sendResponse

Function sendResponse

v1/app/background.js:64–79  ·  view source on GitHub ↗
(socketId, value)

Source from the content-addressed store, hash-verified

62
63// action functions
64var sendResponse = function(socketId, value) {
65 var contentType = "text/plain";
66 var contentLength = encodeURI(value).split(/%..|./).length - 1;;
67 var header = stringToUint8Array(
68 "HTTP/1.0 200 OK\nAccess-Control-Allow-Origin: *\nContent-length: " +
69 contentLength + "\nContent-type:" + contentType + "\n\n");
70 var content = stringToUint8Array(value)
71 var outputBuffer = new ArrayBuffer(header.byteLength + contentLength);
72
73 var view = new Uint8Array(outputBuffer)
74 view.set(header, 0);
75 view.set(stringToUint8Array(value), header.byteLength);
76 socket.write(socketId, outputBuffer, function(writeInfo) {
77 socket.destroy(socketId);
78 });
79};
80
81var readFromSocket = function(socketId) {
82

Callers 2

handleRequestFunction · 0.85
endRequestFunction · 0.85

Calls 1

stringToUint8ArrayFunction · 0.85

Tested by

no test coverage detected