-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from tinyhttp/limits
feat: Request limits
- Loading branch information
Showing
13 changed files
with
1,164 additions
and
795 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
{ | ||
"npm.packageManager": "pnpm", | ||
"editor.formatOnSave": true, | ||
"biome.enabled": true, | ||
"editor.defaultFormatter": "biomejs.biome", | ||
"prettier.enable": false, | ||
"eslint.enable": false, | ||
"prettier.enable": false, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll": "always" | ||
}, | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"[typescript]": { | ||
"editor.defaultFormatter": "biomejs.biome" | ||
"source.fixAll": "explicit", | ||
"source.organizeImports.biome": "explicit" | ||
}, | ||
"[javascript]": { | ||
"editor.defaultFormatter": "biomejs.biome" | ||
} | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
this is a file that is being sent in a multipart request |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { createReadStream } from 'node:fs' | ||
// @ts-check | ||
import { createServer } from 'node:http' | ||
import formidable from 'formidable' | ||
|
||
const form = formidable({}) | ||
|
||
const server = createServer((req, res) => { | ||
form.parse(req, (_, fields, files) => { | ||
// @ts-expect-error this is JS | ||
const file = createReadStream(files.file[0].filepath) | ||
file.pipe(res) | ||
}) | ||
}) | ||
|
||
server.listen(3005) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// @ts-check | ||
|
||
import { createServer } from 'node:http' | ||
import * as bodyParser from '../dist/index.js' | ||
const mw = bodyParser.multipart() | ||
|
||
const server = createServer((req, res) => { | ||
mw(req, res, () => { | ||
/** | ||
* @type {File} | ||
*/ | ||
// @ts-ignore | ||
const file = req.body.file[0] | ||
const stream = file.stream() | ||
|
||
// Pipe the stream to the response | ||
stream.pipeTo( | ||
new WritableStream({ | ||
write(chunk) { | ||
res.write(chunk) | ||
}, | ||
close() { | ||
res.end() | ||
}, | ||
abort(err) { | ||
console.error('Stream error:', err) | ||
res.writeHead(500) | ||
res.end('Error streaming file') | ||
} | ||
}) | ||
) | ||
}) | ||
}) | ||
|
||
server.listen(3004) |
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
Oops, something went wrong.