Giter Site home page Giter Site logo

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

dan-hammond avatar dan-hammond commented on June 19, 2024 3
DELETE requests add a "Content-Length: 0" header, causing undici to error "Request body length does not match content-length header"

from httpxy.

Comments (6)

brc-dd avatar brc-dd commented on June 19, 2024 3

undici fixed this in nodejs/undici#2046 , but not sure if it'll be backported to LTS. I'm using nitro.experimental.nodeFetchCompat till that fix makes to a node LTS 👀

from httpxy.

wug-ge avatar wug-ge commented on June 19, 2024 2

I'm facing the same issue using Nuxt,js routeRules proxy and my DELETE requests don't work.

Putting

delete opts.fetchOptions.headers['content-length']

before this line

https://github.com/unjs/h3/blob/12ccb81432a62783fe951a8170976c8162bce44a/src/utils/proxy.ts#L77

solves my issue, otherwise it fails with a UND_ERR_REQ_CONTENT_LENGTH_MISMATCH.

I'm haven't digged deep enough into the ecosystem to understand fully what's going on, I'd really appreciate if someone could explain further what exactly is happening / provide a workaround.

For now I might have to use a different proxy.

If wanted, I'm happy to do some digging myself. (not sure how efficient I'll be here though)

from httpxy.

brc-dd avatar brc-dd commented on June 19, 2024 2

You might also need to disable built-in fetch. I'm using this kind of setup:

// package.json

  "scripts": {
    "dev": "pnpm nuxt dev",
    "build": "pnpm nuxt build",
    "generate": "pnpm nuxt generate",
    "preview": "pnpm nuxt preview",
    "postinstall": "pnpm nuxt prepare",
    "nuxt": "NODE_OPTIONS='--no-experimental-fetch' nuxt"
  }
// nuxt.config.ts

export default defineNuxtConfig({
  nitro: {
    experimental: {
      nodeFetchCompat: true
    }
  }
})

At the time I posted that comment, it was working fine just by setting in nuxt.config, but broke between some Nuxt minor IG. So you might need to add both. I have confirmed that it works fine in latest Node.js without any extra config, so probably this issue can be closed as I think this was always an upstream issue.

PS: I just read [email protected] release notes and looks like it should now work fine on latest LTS too. 🎉

from httpxy.

pi0 avatar pi0 commented on June 19, 2024

Thanks for the issue. Related upstream issues http-party/node-http-proxy#1343 and nodejs/node#27880

This feature was originally introduced in http-proxy via http-party/node-http-proxy#742 as part of bug fix for nginx and chunked streaming. I will have to check it more in defails.

Anyway i think it is a valid bug if we are overriding the existing content-length.

from httpxy.

wug-ge avatar wug-ge commented on June 19, 2024

@brc-dd can you explain what you mean by using nitro.experimental.nodeFetchCompat?

I can't find much about it, what it is and how do I set it in my Nuxt config? 😄

I tested this issue with node 18, 20 and 21 and it persists in all versions. My current workaround is to add something random in the body of the DELETE request, which is quiet ugly...

from httpxy.

Denoder avatar Denoder commented on June 19, 2024

@wug-ge

export default defineNuxtConfig({
    nitro: {
        experimental: {
            nodeFetchCompat: true
        }
    }
})

from httpxy.

Related Issues (13)

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.