GithubHelp home page GithubHelp logo

backendstack21 / 0http Goto Github PK

View Code? Open in Web Editor NEW
150.0 150.0 11.0 198 KB

Zero friction HTTP requests router. The need for speed!

Home Page: https://0http.21no.de

License: MIT License

JavaScript 100.00%

0http's People

Contributors

jesusvilla avatar jkyberneees avatar schamberg97 avatar silverwind avatar spurreiter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

0http's Issues

String.prototype.replaceAll is supported in Node >= 15

File: /lib/utils/queryparams.js
Line 3: new URLSearchParams(search.replaceAll('[]=', '='))

The string function 'replaceAll' is only supported in Node >= 15.
This is a breaking change which is causing everything to collapse

uWS reqWrapper not being a Stream

Hey there again! I've been working on my side project that uses code from low library, as well as outstanding issues in this project. However, I figured out that only resWrapper class extends a Writeable Stream. http.IncomingMessage extends Readable Stream, but reqWrapper does not, which breaks a lot of middlewares, especially raw-body and (by extension) body-parser. This is partially fixable through ugly hacks or a rewrite of reqWrapper (which would require a new major semver). However, I am curious to know, whether there are any specific reasons why low library does not implement reqWrapper as a Readabale Stream?

Uncaught exception in low implementation.

🐛 Bug Report

Server crash when aborting wrk when using fast-proxy with 0http with low server
Ref: fastify/fast-proxy#35

To Reproduce

I have the following code:
(Happens also without undici)

    const { proxy } = fastProxy({
      base: 'http://localhost:4000',
      undiciOptions: {
        connections: 4000,
        pipelining: 20,
        requestTimeout: 5000,
      },
    });
    const { router, server } = cero({
      server: low(),
    });

    router.all('/*', (req, res) => proxy(req, res, req.url, {}));

    server.listen(3000, (socket) => {
      if (socket) {
        console.log('HTTP server ready!');
      }
    });

With an additional restana server listening on port 4000
Then run
wrk -t8 -c50 -d20s http://localhost:3000/api/v1/test
hit CTRL-C to stop wrk.

Result:
process abort on with the following error:

Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse.
There was an uncaught exception. I'm now going to commit suicide; farewell all.

When I'm using 0http without low it doesn’t happen

Expected behavior

The process should not abort if I stop wrk

Your Environment

  • node version: 12
  • fast-prxy version: latest
  • os: Mac

This expression is not callable error when initializing router and server

Describe the bug
This expression is not callable. error when using 0http.

To Reproduce

import cero from '0http';
const { router, server } = cero();
server.listen(3000);

Expected behavior
cero should be able to be called and the router and server should be able to be used.

Additional context
0http version: 3.5.1
typescript version: 5.0.4

Feature request: Replace legacy dependency for querystring parsing with URLSearchParams

IMHO there is no need to relay on the legacy querystring.parse method any longer, which is used in https://github.com/BackendStack21/0http/blob/master/lib/utils/queryparams.js .

Is there a chance to replace it with the native URLSearchParams?
Maybe this gives an additional performance boost?

E.g.

module.exports = (req, url) => {
  const [path, search] = url.split('?')
  const searchParams = new URLSearchParams(search.replace(/\[\]=/g, '='))
  req.path = path
  req.query = Object.fromEntries(searchParams)
}

Low Server: Cannot use pipe with response

First, I want to congratulate you on doing something so simple to use, but so fast.
Both natively and with expressjs (I think that competing against this framework does not hurt you) you can use pipe on the response object in the router, but can't when using low server.

const low = require('0http/lib/server/low')
const cero = require('0http')

const { router, server } = cero({
  server: low()
})

router.get('/image.png', (req, res) => {
  res.setHeader('Content-Type', 'image/png')

  const { createReadStream } = require('fs')
  const readStream = createReadStream('./test.png')
  readStream.pipe(res)
})

server.listen(3000, (socket) => {
  if (socket) {
    console.log('HTTP server ready!')
  }
})

Considerations:

To achieve that, the response object must be a Writable Stream.

Using sessions in 0http?

Just asking if it's possible to use sessions (similar to express-session) in 0http?

Or if there is any known implementation of such

Typescript example/support

how can I use this with typescript? or it only supports javascript as of now? An example would be very helpful if it supports typescript.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.