Giter Site home page Giter Site logo

httpxy's People

Contributors

atinux avatar didavid61202 avatar gacek1123 avatar jonasolesen avatar pi0 avatar renovate[bot] avatar siddiquipro 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

httpxy's Issues

Relative URL for Location response header causes TypeError (e.g. 201 Created)

Environment

httpxy 0.1.5
node 20 (but doesn't really matter)

Reproduction

not needed, I think

Describe the bug

If the server responds with a relativ URL in the Location header (e.g. in case of 201 Created), it causes an "Uncaught TypeError: Invalid URL" error, since there is no second parameter to the URL constructor in:

const u = new URL(proxyRes.headers.location);

For example:

HTTP/1.1 201 Created
Location: /api/books/1

Additional context

The Location response header is allowed to contain a relativ URL, according to: https://www.rfc-editor.org/rfc/rfc9110#field.location

The URL constructor needs a base argument in that case: https://nodejs.org/api/url.html#new-urlinput-base

Logs

No response

All unjs official code base documentation is very poor

Describe the change

import { createServer } from "node:http";

import { createProxyServer } from "httpxy";

const proxy = createProxyServer({});

const server = createServer(async (req, res) => {
  try {
    await proxy.web(req, res, {
      target: main.url,
    });
  } catch (error) {
    console.error(error);
    res.statusCode = 500;
    res.end("Proxy error: " + error.toString());
  }
});

server.listen(3000, () => {
  console.log("Proxy is listening on http://localhost:3000");
});

The above code runs with an error
image
image

URLs

No response

Additional information

  • Would you be willing to help?

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>unjs/renovate-config)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/autofix.yml
  • actions/checkout v4
  • actions/setup-node v3
  • autofix-ci/action ea32e3a12414e6d3183163c3424a7d7a8631ad84
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/setup-node v3
  • codecov/codecov-action v3
npm
package.json
  • @types/node ^20.11.25
  • @vitest/coverage-v8 ^0.34.6
  • changelogen ^0.5.5
  • eslint ^8.57.0
  • eslint-config-unjs ^0.2.1
  • jiti ^1.21.0
  • listhen ^1.7.2
  • ofetch ^1.3.3
  • prettier ^3.2.5
  • typescript ^5.4.2
  • unbuild ^2.0.0
  • vitest ^0.34.6
  • pnpm 8.15.4

  • Check this box to trigger a request for Renovate to run again on this repository

WTF? I encountered a problem and asked for a solution. Did you close my issue?

Environment

  • debian
  • nodejs 18

Reproduction

Use the official tutorial

Describe the bug

Describe the change

import { createServer } from "node:http";

import { createProxyServer } from "httpxy";

const proxy = createProxyServer({});

const server = createServer(async (req, res) => {
  try {
    await proxy.web(req, res, {
      target: main.url,
    });
  } catch (error) {
    console.error(error);
    res.statusCode = 500;
    res.end("Proxy error: " + error.toString());
  }
});

server.listen(3000, () => {
  console.log("Proxy is listening on http://localhost:3000");
});

The above code runs with an error
image
image

URLs

No response

Additional information

  • Would you be willing to help?

Additional context

No response

Logs

No response

Rewrite request and response (MITM proxy)

Describe the feature

It could be a very nice feature to be able to rewrite request and response headers/body.

The goal would be to have a full-featured MITM proxy with programmatic rules that trigger based on patterns
e.g. on hostname my-domain.com, run the provided function

Something like Charles Proxy or Burp Proxy, but with a modern syntax and access to the wide JavaScript dependencies ecosystem

TLS encryption-decryption should be implemented so that we can MITM HTTPS connections.

What do you think?

Additional information

  • Would you be willing to help implement this feature?

UNIX socket support

Describe the feature

Hi,

It would be really nice if we could proxy to a UNIX socket :-)

Thanks in advance!

I would happily help implement this feature but can't do it myself right now due to time constraints (I already helped implement a similar feature in listhen)

Additional information

  • Would you be willing to help implement this feature?

Target path is not being set correctly when prepending path

Environment

Package version 0.1.2
Node.js 18.16.0

Reproduction

I initially reproduced the error by using nitro and configuring the devProxy like so:

devProxy: {
  "/posts": {
    target: "https://jsonplaceholder.typicode.com/posts",
    changeOrigin: true,
    prependPath: true,
  },
},

It turned out to be a bug with httpxy instead, but I figured the reproduction would be obvious enough using the nitro playground with the above configuration rather than forking the repo.

Describe the bug

Using the provided configuration, I assume the expected behavior would be to proxy a request to the /posts path to https://jsonplaceholder.typicode.com/posts, but it seems to be forwarded to just https://jsonplaceholder.typicode.com instead. I (supposedly) fixed the bug by changing the property used when determining the target path from path to pathname as per the URL class API documentation. I'll submit a PR shortly.

Additional context

Another issue reporting the bug: unjs/nitro#1643

Logs

No response

DELETE requests add a "Content-Length: 0" header, causing undici to error "Request body length does not match content-length header"

Environment

  • Operating System: Darwin
  • Node Version: v20.5.1
  • Nuxt Version: 3.7.0
  • CLI Version: 3.7.2
  • Nitro Version: 2.6.2
  • Package Manager: [email protected]
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

I confess I haven't made one up-front. I think the explanation below might be enough, but if not I can try to figure out a reproduction.

Describe the bug

When making a DELETE request, the request has a "Content-Length: 0" header added to it, which causes Node's undici to respond with the following error:

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11576:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async sendProxy (file:///myprojectpath/node_modules/h3/dist/index.mjs:1049:20)
    at async Object.handler (file:///myprojectpath/node_modules/h3/dist/index.mjs:1646:19)
    at async Server.toNodeHandle (file:///myprojectpath/node_modules/h3/dist/index.mjs:1857:7) {
  cause: RequestContentLengthMismatchError: Request body length does not match content-length header
      at write (node:internal/deps/undici/undici:10059:41)
      at _resume (node:internal/deps/undici/undici:10037:33)
      at resume (node:internal/deps/undici/undici:9938:7)
      at [dispatch] (node:internal/deps/undici/undici:9286:11)
      at Client.Intercept (node:internal/deps/undici/undici:9017:20)
      at Client.dispatch (node:internal/deps/undici/undici:7772:44)
      at [dispatch] (node:internal/deps/undici/undici:7991:32)
      at Pool.dispatch (node:internal/deps/undici/undici:7772:44)
      at [dispatch] (node:internal/deps/undici/undici:10556:27)
      at Agent.Intercept (node:internal/deps/undici/undici:9017:20) {
    code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
  }

More context has been provided here:
nodejs/undici#2046 (comment)

Here's the same code in this fork:

* Sets `content-length` to '0' if request is of DELETE type.

This is all somewhat beyond me, but I would think it's not the responsibility of the proxy to be adding HTTP headers that weren't provided in the initial request, unless it's intentional behaviour written in middleware or proxy route rules.

I appreciate that Node may end up fixing their underlying behaviour to allow DELETE requests with a Content-Length, but that may not solve the problem for people proxying to other non-JS back-ends.

Similarly, I have read in the linked undici issue that Safari does send Content-Length: 0 with DELETE requests, so it would be useful to know how I can filter those out. I am using extendRouteRules in a Nuxt module to register my proxy rules, and am doing so as a wildcard for a whole path prefix. Is that currently possible?

Additional context

No response

Logs

No response

Enable ts strict checks

Initially disabled to make refactor faster. It should be straight forward now if someone wants to pick this.

Triage from upstream issues and PRs

Support HTTP2/3

Describe the feature

Support for HTTP2/3 in order to be a replacement for Vite dev-server and other build tools.

Upstream: http-party/node-http-proxy#1237

Additional information

  • Would you be willing to help implement this feature?

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.