Created
June 8, 2018 16:28
-
-
Save mike-marcacci/5c7f435d51240feb8a871ab348a00dfd to your computer and use it in GitHub Desktop.
Testing http/https/http2
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
const fs = require("fs"); | |
const http = require("http"); | |
const https = require("https"); | |
const http2 = require("http2"); | |
const form = ` | |
<html> | |
<body> | |
<script> | |
const send = () => { | |
const formData = new FormData(); | |
const nameField = document.querySelector("input[name='name']"); | |
const fileField = document.querySelector("input[name='file']"); | |
formData.append('name', nameField.value); | |
formData.append('file', fileField.files[0]); | |
fetch('/', { method: 'POST', body: formData }); | |
} | |
</script> | |
<form action="/" method="post" enctype="multipart/form-data"> | |
<input name="name" type="text" value="Name" /> | |
<input name="file" type="file" /> | |
<input type="submit" /> | |
</form> | |
<button type="button" onclick="send()">Fetch</button> | |
</body> | |
</html> | |
`; | |
http | |
.createServer( | |
{ | |
key: fs.readFileSync("./localhost.key"), | |
cert: fs.readFileSync("./localhost.crt"), | |
}, | |
(req, res) => { | |
req.pipe(fs.createWriteStream("8000.txt")); | |
console.log("SENT") | |
res.writeHead(200); | |
res.end(form); | |
} | |
) | |
.listen(8000, "localhost"); | |
https | |
.createServer( | |
{ | |
key: fs.readFileSync("./localhost.key"), | |
cert: fs.readFileSync("./localhost.crt"), | |
}, | |
(req, res) => { | |
req.pipe(fs.createWriteStream("8001.txt")); | |
res.writeHead(200); | |
res.end(form); | |
} | |
) | |
.listen(8001, "localhost"); | |
http2 | |
.createSecureServer( | |
{ | |
key: fs.readFileSync("./localhost.key"), | |
cert: fs.readFileSync("./localhost.crt"), | |
allowHTTP1: false | |
}, | |
(req, res) => { | |
req.pipe(fs.createWriteStream("8002.txt")); | |
res.writeHead(200); | |
res.end(form); | |
} | |
) | |
.listen(8002, "localhost"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment