Skip to content

Commit

Permalink
fix uppercase http Content-type in examples and tests
Browse files Browse the repository at this point in the history
req.headers are lowercased by node (when received)
however when sent they should be capitalized
this commit does only change examples and readme
  • Loading branch information
GrosSacASac committed Dec 13, 2020
1 parent 8a0ffe8 commit 76ad4ae
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -112,15 +112,15 @@ const server = http.createServer((req, res) => {
const form = formidable({ multiples: true });

form.parse(req, (err, fields, files) => {
res.writeHead(200, { 'content-type': 'application/json' });
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ fields, files }, null, 2));
});

return;
}

// show a file upload form
res.writeHead(200, { 'content-type': 'text/html' });
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(`
<h2>With Node.js <code>"http"</code> module</h2>
<form action="/api/upload" enctype="multipart/form-data" method="post">
Expand Down
8 changes: 4 additions & 4 deletions examples/json.js
Expand Up @@ -7,7 +7,7 @@ const { formidable } = require('../src/index');
const PORT = 3000;
const server = http.createServer((req, res) => {
if (req.method !== 'POST') {
res.writeHead(200, { 'content-type': 'text/plain' });
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end(`Please POST a JSON payload to http://localhost:${PORT}/`);
return;
}
Expand All @@ -18,7 +18,7 @@ const server = http.createServer((req, res) => {
form
.on('error', (err) => {
console.error(err);
res.writeHead(500, { 'content-type': 'text/plain' });
res.writeHead(500, { 'Content-Type': 'text/plain' });
res.end(`error:\n\n${util.inspect(err)}`);
})
.on('field', (field, value) => {
Expand All @@ -27,7 +27,7 @@ const server = http.createServer((req, res) => {
})
.on('end', () => {
console.log('-> post done from "end" event');
res.writeHead(200, { 'content-type': 'text/plain' });
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end(`received fields:\n\n${util.inspect(fields)}`);
});

Expand All @@ -50,7 +50,7 @@ server.listen(PORT, () => {
port: choosenPort,
method: 'POST',
headers: {
'content-type': 'application/json',
'Content-Type': 'application/json',
'content-length': body.length,
},
},
Expand Down
6 changes: 3 additions & 3 deletions examples/multiples.js
Expand Up @@ -6,7 +6,7 @@ const { Formidable } = require('../src/index');

const server = http.createServer((req, res) => {
if (req.url === '/') {
res.writeHead(200, { 'content-type': 'text/html' });
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(`
<form action="/upload" enctype="multipart/form-data" method="post">
<label>simple<input type="text" name="text_single" autofocus /></label><br />
Expand All @@ -31,11 +31,11 @@ const server = http.createServer((req, res) => {
const form = new Formidable({ multiples: true, uploadDir: os.tmpdir() });

form.parse(req, (err, fields, files) => {
res.writeHead(200, { 'content-type': 'application/json' });
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ err, fields, files }, null, 2));
});
} else {
res.writeHead(404, { 'content-type': 'text/plain' });
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('404');
}
});
Expand Down
6 changes: 3 additions & 3 deletions examples/upload-multiple-files.js
Expand Up @@ -8,7 +8,7 @@ const { Formidable } = require('../src/index');

const server = http.createServer((req, res) => {
if (req.url === '/') {
res.writeHead(200, { 'content-type': 'text/html' });
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(`
<form action="/upload" enctype="multipart/form-data" method="post">
<input type="text" name="title"><br>
Expand All @@ -32,15 +32,15 @@ const server = http.createServer((req, res) => {
})
.on('end', () => {
console.log('-> upload done');
res.writeHead(200, { 'content-type': 'text/plain' });
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write(`received fields:\n\n${util.inspect(fields)}`);
res.write('\n\n');
res.end(`received files:\n\n${util.inspect(files)}`);
});

form.parse(req);
} else {
res.writeHead(404, { 'content-type': 'text/plain' });
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('404');
}
});
Expand Down
10 changes: 5 additions & 5 deletions examples/urlencoded-no-enctype.js
Expand Up @@ -7,7 +7,7 @@ const { Formidable } = require('../src/index');

const server = http.createServer((req, res) => {
if (req.url === '/') {
res.writeHead(200, { 'content-type': 'text/html' });
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(`
<form action="/post" method="post">
Title: <input type="text" name="title" /><br />
Expand All @@ -22,7 +22,7 @@ const server = http.createServer((req, res) => {
form
.on('error', (err) => {
console.log('err!', err);
res.writeHead(200, { 'content-type': 'text/plain' });
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end(`error:\n\n${util.inspect(err)}`);
})
.on('field', (fieldName, fieldValue) => {
Expand All @@ -33,17 +33,17 @@ const server = http.createServer((req, res) => {
})
.on('end', () => {
console.log('-> post done from "end" event');
res.writeHead(200, { 'content-type': 'text/plain' });
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end(`received fields:\n\n${util.inspect(fields)}`);
});

form.parse(req, () => {
console.log('-> post done from callback');
// res.writeHead(200, { 'content-type': 'text/plain' });
// res.writeHead(200, { 'Content-Type': 'text/plain' });
// res.end(`received fields:\n\n${util.inspect(fields)}`);
});
} else {
res.writeHead(404, { 'content-type': 'text/plain' });
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('404');
}
});
Expand Down
4 changes: 2 additions & 2 deletions examples/with-http.js
Expand Up @@ -9,15 +9,15 @@ const server = http.createServer((req, res) => {
const form = formidable({ multiples: true });

form.parse(req, (err, fields, files) => {
res.writeHead(200, { 'content-type': 'application/json' });
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ fields, files }, null, 2));
});

return;
}

// show a file upload form
res.writeHead(200, { 'content-type': 'text/html' });
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(`
<h2>With Node.js <code>"http"</code> module</h2>
<form action="/api/upload" enctype="multipart/form-data" method="post">
Expand Down
4 changes: 2 additions & 2 deletions test/standalone/test-issue-46.js
Expand Up @@ -18,15 +18,15 @@ const indexForm = `
const server = http.createServer((req, res) => {
// Show a form for testing purposes.
if (req.method === 'GET') {
res.writeHead(200, { 'content-type': 'text/html' });
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(indexForm);
return;
}

// Parse form and write results to response.
const form = formidable();
form.parse(req, (err, fields, files) => {
res.writeHead(200, { 'content-type': 'text/plain' });
res.writeHead(200, { 'Content-Type': 'text/plain' });
// ? old, makes more sense to be passed to `.end()`?
// res.write(JSON.stringify({ err, fields, files }));
res.end(JSON.stringify({ err, fields, files }));
Expand Down
2 changes: 1 addition & 1 deletion tool/record.js
Expand Up @@ -20,7 +20,7 @@ const server = http.createServer((req, res) => {
return;
}

res.writeHead(200, { 'content-type': 'text/html' });
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(
'<form action="/upload" enctype="multipart/form-data" method="post">' +
'<input type="text" name="title"><br>' +
Expand Down

0 comments on commit 76ad4ae

Please sign in to comment.