Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
h3-compression
Advanced tools
Handles compression for H3
✔️ Zlib Compression: You can use zlib compression (brotli, gzip and deflate)
✔️ Stream Compression: You can use native stream compressions (gzip, deflate)
✔️ Compression Detection: It uses the best compression which is accepted
# Using npm
npm install h3-compression
# Using yarn
yarn add h3-compression
# Using pnpm
pnpm add h3-compression
import { createServer } from 'node:http'
import { createApp, eventHandler, toNodeListener } from 'h3'
import { useCompressionStream } from 'h3-compression'
const app = createApp({ onBeforeResponse: useCompressionStream }) // or { onBeforeResponse: useCompression }
app.use(
'/',
eventHandler(() => 'Hello world!'),
)
createServer(toNodeListener(app)).listen(process.env.PORT || 3000)
Example using listhen for an elegant listener:
import { createApp, eventHandler, toNodeListener } from 'h3'
import { listen } from 'listhen'
import { useCompressionStream } from 'h3-compression'
const app = createApp({ onBeforeResponse: useCompressionStream }) // or { onBeforeResponse: useCompression }
app.use(
'/',
eventHandler(() => 'Hello world!'),
)
listen(toNodeListener(app))
If you want to use it in nuxt 3 you can define a nitro plugin.
server/plugins/compression.ts
import { useCompression } from 'h3-compression'
export default defineNitroPlugin((nitro) => {
nitro.hooks.hook('render:response', async (response, { event }) => {
if (!response.headers?.['content-type'].startsWith('text/html'))
return
await useCompression(event, response)
})
})
[!NOTE]
useCompressionStream
doesn't work right now in nitro. So you just can useuseCompression
H3-compression has a concept of composable utilities that accept event
(from eventHandler((event) => {})
) as their first argument and response
as their second.
useGZipCompression(event, response)
useDeflateCompression(event, response)
useBrotliCompression(event, response)
useCompression(event, response)
useGZipCompressionStream(event, response)
useDeflateCompressionStream(event, response)
useCompressionStream(event, response)
MIT License © 2023-PRESENT Gregor Becker
FAQs
Adds compression to h3 request (brotli, gzip, deflate)
The npm package h3-compression receives a total of 50,918 weekly downloads. As such, h3-compression popularity was classified as popular.
We found that h3-compression demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.