Skip to content

Commit 76ad4ae

Browse files
committed
fix uppercase http Content-type in examples and tests
req.headers are lowercased by node (when received) however when sent they should be capitalized this commit does only change examples and readme
1 parent 8a0ffe8 commit 76ad4ae

File tree

8 files changed

+22
-22
lines changed

8 files changed

+22
-22
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ const server = http.createServer((req, res) => {
112112
const form = formidable({ multiples: true });
113113

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

119119
return;
120120
}
121121

122122
// show a file upload form
123-
res.writeHead(200, { 'content-type': 'text/html' });
123+
res.writeHead(200, { 'Content-Type': 'text/html' });
124124
res.end(`
125125
<h2>With Node.js <code>"http"</code> module</h2>
126126
<form action="/api/upload" enctype="multipart/form-data" method="post">

examples/json.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { formidable } = require('../src/index');
77
const PORT = 3000;
88
const server = http.createServer((req, res) => {
99
if (req.method !== 'POST') {
10-
res.writeHead(200, { 'content-type': 'text/plain' });
10+
res.writeHead(200, { 'Content-Type': 'text/plain' });
1111
res.end(`Please POST a JSON payload to http://localhost:${PORT}/`);
1212
return;
1313
}
@@ -18,7 +18,7 @@ const server = http.createServer((req, res) => {
1818
form
1919
.on('error', (err) => {
2020
console.error(err);
21-
res.writeHead(500, { 'content-type': 'text/plain' });
21+
res.writeHead(500, { 'Content-Type': 'text/plain' });
2222
res.end(`error:\n\n${util.inspect(err)}`);
2323
})
2424
.on('field', (field, value) => {
@@ -27,7 +27,7 @@ const server = http.createServer((req, res) => {
2727
})
2828
.on('end', () => {
2929
console.log('-> post done from "end" event');
30-
res.writeHead(200, { 'content-type': 'text/plain' });
30+
res.writeHead(200, { 'Content-Type': 'text/plain' });
3131
res.end(`received fields:\n\n${util.inspect(fields)}`);
3232
});
3333

@@ -50,7 +50,7 @@ server.listen(PORT, () => {
5050
port: choosenPort,
5151
method: 'POST',
5252
headers: {
53-
'content-type': 'application/json',
53+
'Content-Type': 'application/json',
5454
'content-length': body.length,
5555
},
5656
},

examples/multiples.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { Formidable } = require('../src/index');
66

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

3333
form.parse(req, (err, fields, files) => {
34-
res.writeHead(200, { 'content-type': 'application/json' });
34+
res.writeHead(200, { 'Content-Type': 'application/json' });
3535
res.end(JSON.stringify({ err, fields, files }, null, 2));
3636
});
3737
} else {
38-
res.writeHead(404, { 'content-type': 'text/plain' });
38+
res.writeHead(404, { 'Content-Type': 'text/plain' });
3939
res.end('404');
4040
}
4141
});

examples/upload-multiple-files.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { Formidable } = require('../src/index');
88

99
const server = http.createServer((req, res) => {
1010
if (req.url === '/') {
11-
res.writeHead(200, { 'content-type': 'text/html' });
11+
res.writeHead(200, { 'Content-Type': 'text/html' });
1212
res.end(`
1313
<form action="/upload" enctype="multipart/form-data" method="post">
1414
<input type="text" name="title"><br>
@@ -32,15 +32,15 @@ const server = http.createServer((req, res) => {
3232
})
3333
.on('end', () => {
3434
console.log('-> upload done');
35-
res.writeHead(200, { 'content-type': 'text/plain' });
35+
res.writeHead(200, { 'Content-Type': 'text/plain' });
3636
res.write(`received fields:\n\n${util.inspect(fields)}`);
3737
res.write('\n\n');
3838
res.end(`received files:\n\n${util.inspect(files)}`);
3939
});
4040

4141
form.parse(req);
4242
} else {
43-
res.writeHead(404, { 'content-type': 'text/plain' });
43+
res.writeHead(404, { 'Content-Type': 'text/plain' });
4444
res.end('404');
4545
}
4646
});

examples/urlencoded-no-enctype.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { Formidable } = require('../src/index');
77

88
const server = http.createServer((req, res) => {
99
if (req.url === '/') {
10-
res.writeHead(200, { 'content-type': 'text/html' });
10+
res.writeHead(200, { 'Content-Type': 'text/html' });
1111
res.end(`
1212
<form action="/post" method="post">
1313
Title: <input type="text" name="title" /><br />
@@ -22,7 +22,7 @@ const server = http.createServer((req, res) => {
2222
form
2323
.on('error', (err) => {
2424
console.log('err!', err);
25-
res.writeHead(200, { 'content-type': 'text/plain' });
25+
res.writeHead(200, { 'Content-Type': 'text/plain' });
2626
res.end(`error:\n\n${util.inspect(err)}`);
2727
})
2828
.on('field', (fieldName, fieldValue) => {
@@ -33,17 +33,17 @@ const server = http.createServer((req, res) => {
3333
})
3434
.on('end', () => {
3535
console.log('-> post done from "end" event');
36-
res.writeHead(200, { 'content-type': 'text/plain' });
36+
res.writeHead(200, { 'Content-Type': 'text/plain' });
3737
res.end(`received fields:\n\n${util.inspect(fields)}`);
3838
});
3939

4040
form.parse(req, () => {
4141
console.log('-> post done from callback');
42-
// res.writeHead(200, { 'content-type': 'text/plain' });
42+
// res.writeHead(200, { 'Content-Type': 'text/plain' });
4343
// res.end(`received fields:\n\n${util.inspect(fields)}`);
4444
});
4545
} else {
46-
res.writeHead(404, { 'content-type': 'text/plain' });
46+
res.writeHead(404, { 'Content-Type': 'text/plain' });
4747
res.end('404');
4848
}
4949
});

examples/with-http.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ const server = http.createServer((req, res) => {
99
const form = formidable({ multiples: true });
1010

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

1616
return;
1717
}
1818

1919
// show a file upload form
20-
res.writeHead(200, { 'content-type': 'text/html' });
20+
res.writeHead(200, { 'Content-Type': 'text/html' });
2121
res.end(`
2222
<h2>With Node.js <code>"http"</code> module</h2>
2323
<form action="/api/upload" enctype="multipart/form-data" method="post">

test/standalone/test-issue-46.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ const indexForm = `
1818
const server = http.createServer((req, res) => {
1919
// Show a form for testing purposes.
2020
if (req.method === 'GET') {
21-
res.writeHead(200, { 'content-type': 'text/html' });
21+
res.writeHead(200, { 'Content-Type': 'text/html' });
2222
res.end(indexForm);
2323
return;
2424
}
2525

2626
// Parse form and write results to response.
2727
const form = formidable();
2828
form.parse(req, (err, fields, files) => {
29-
res.writeHead(200, { 'content-type': 'text/plain' });
29+
res.writeHead(200, { 'Content-Type': 'text/plain' });
3030
// ? old, makes more sense to be passed to `.end()`?
3131
// res.write(JSON.stringify({ err, fields, files }));
3232
res.end(JSON.stringify({ err, fields, files }));

tool/record.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const server = http.createServer((req, res) => {
2020
return;
2121
}
2222

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

0 commit comments

Comments
 (0)