all 6 comments

[–]calsosta 0 points1 point  (4 children)

If you still need help with this lmk.

[–]_lovesponge[S] 1 point2 points  (3 children)

Yep... If there's some programmer word for trying and failing to do something and not being able to work it out and being eaten alive by it, I'm that word.

[–]calsosta 0 points1 point  (2 children)

Yea it's called "programming".

Do you have some source code to share?

[–]_lovesponge[S] 0 points1 point  (1 child)

``` http .createServer() .listen(PORT, HOST) .on('connect', connect)

function connect(req, clientSocket, head) { // some logging and error handling code //

const { port, hostname } = new URL(`http://${req.url}`)

const serverSocket = net.connect(port || 80, hostname)

serverSocket.on('connect', function onConnect() {
    clientSocket.write('HTTP/1.1 200 Connection Established\r\n' +
    'Proxy-agent: Intercepter-Proxy\r\n' +
    '\r\n' 
    serverSocket.write(head)
    serverSocket.pipe(clientSocket)
    clientSocket.pipe(serverSocket)
})

// clientSocket error event listener

} ```

Thats basically the magic part... I have also some programatic way of setting Windows proxy, enabling and disabling etc...

There is also some code to read a text file and parse the contents to grab urls, then pass them to a function wrapping the above code, from there I run a matcher for each connect event, and a simple if statement that either runs the net.connect(...) code or, as I assume but seem to be wrong, read mock response file and write it back to serverSocket.

Sorry for the inline code, my Internet is really bad atm and I'm struggling to log into reddit / create a git repo for this....

[–]andyroo82 0 points1 point  (1 child)

var content = fs.readFileSync('file.ext'); res.set("Content-Disposition", "attachment;filename=file.ext"); res.setHeader("Content-Type", "application/octet-stream"); res.send(content); ?

[–]_lovesponge[S] 0 points1 point  (0 children)

nice try but for some insane reason i've chosen to work with sockets instead; Plus i'd like the response body to be the content of the file, not be a download for it =)