Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy not work for post #2377

Closed
snadn opened this issue Nov 28, 2020 · 12 comments
Closed

proxy not work for post #2377

snadn opened this issue Nov 28, 2020 · 12 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@snadn
Copy link

snadn commented Nov 28, 2020

POST request body is not proxied to the servers. Maybe the same problem as chimurai/http-proxy-middleware#40

  • Web Browser: chrome 86
  • Local OS: macOS 10.13
  • Remote OS: docker
  • code-server --version: 3.7.4
  1. start a server in code-server terminal
  2. post to server without header 'application/json' by proxy, the server receive body
  3. post to server with header 'application/json' by proxy, the server can not receive body
@nhooyr
Copy link
Contributor

nhooyr commented Nov 30, 2020

Please fill in the issue template!

And make sure you're authed to the proxy.

And see #2128

@nhooyr nhooyr added the waiting-for-info Waiting for more information from submitter label Nov 30, 2020
@snadn
Copy link
Author

snadn commented Dec 13, 2020

@nhooyr
I have added the steps to reproduce the problem in the issue, and I start code-server with config auth: none

@nhooyr nhooyr added bug Something isn't working and removed waiting-for-info Waiting for more information from submitter labels Dec 14, 2020
@nhooyr
Copy link
Contributor

nhooyr commented Dec 14, 2020

@snadn There is no header application/json. Are you referring to Accept or Content-Type?

@nhooyr nhooyr added the waiting-for-info Waiting for more information from submitter label Dec 14, 2020
@snadn
Copy link
Author

snadn commented Dec 15, 2020

@nhooyr I mean Content-Type

@Inlustra
Copy link

Inlustra commented Dec 15, 2020

@snadn I'm seeing the same issues as you.
Server never receives the post and instead just hangs forever.

(Until I get a 502, Socket hang up)

I hadn't updated in a long while, and after I did, then I was seeing this issue
In my case, I'm hosting via a domain name behind SSL, though the SSL is terminated elsewhere, e.g: 1234.mywebsite.com/graphql

@scumbug
Copy link

scumbug commented Dec 15, 2020

Running an express server and have the same issue trying to get POST request body of types application/json and application/x-www-form-urlencoded (Just hangs until I kill the server or 502 after awhile)

Tried both body-parser and express.json()/express.urlencoded with no success

multipart/form-data works fine using multer to parse the data

@BenBJD
Copy link

BenBJD commented Dec 19, 2020

I have the same problem with a Flask server.

Going local to port 5000 on my server it works perfectly, but proxying through code-server by http://code.domain.co.uk/proxy/5000/user/login causes curl and flask to hang until I ctrl-c. This is only happens with POST requests. GET requests work perfectly. The same happens if i access code-server locally by port 8443. I used the network tab of Firefox dev tools to send a request with more control, and instead of a hang I just got a 400 bad request. I disabled auth with auth: none in config.yaml to make sure it wasn't to do with that.

Using a breakpoint I found it was on the first line in the route which was user = request.form["user"] that was hanging, which means the value user must not be in the body of the POST request. So it seems pretty obvious for some reason the POST body isn't getting through the code-server proxy to flask. If it matters, I am running code server through an nginx reverse proxy along the lines of this with an extra few lines for a custom font.

@Inlustra
Copy link

Inlustra commented Dec 22, 2020

@nhooyr Do you need more info than what has been posted?

@BenBJD
Copy link

BenBJD commented Dec 22, 2020

I managed to fix the issue (I think) but the yarn watch thing gives me a [tsc] src/node/routes/pathProxy.ts:38:13 - error TS2339: Property 'body' does not exist on type 'IncomingMessage'. for the 3 times i used req.body. My test express server did receive the body despite this so I think the fix worked. I only did it for the subfolder proxies for now because they were easier to test and I had to learn what express is to do this so it might not be perfect although it looks like it might be the same fix in the domainProxy.ts file

My edited pathProxy.ts is here

@lhaley2011
Copy link

If it is helpful, I use linuxserver's builds of code-server. It looks like the proxy issue started between versions 3.6.2 and 3.7.4. Build 3.6.2 will work if you roll back to it.

@nhooyr nhooyr removed the waiting-for-info Waiting for more information from submitter label Jan 20, 2021
@nhooyr
Copy link
Contributor

nhooyr commented Jan 20, 2021

Confirmed this, working on a fix!

Also added a test to prevent any future breakage in this area!

@nhooyr nhooyr self-assigned this Jan 20, 2021
@nhooyr nhooyr added this to the v3.8.1 milestone Jan 20, 2021
nhooyr added a commit to nhooyr/code-server that referenced this issue Jan 20, 2021
nhooyr added a commit to nhooyr/code-server that referenced this issue Jan 20, 2021
This allows the http-proxy package to passthrough the request body
correctly. Closes coder#2377
nhooyr added a commit to nhooyr/code-server that referenced this issue Jan 20, 2021
This allows the http-proxy package to passthrough the request body
correctly. Closes coder#2377
nhooyr added a commit to nhooyr/code-server that referenced this issue Jan 20, 2021
nhooyr added a commit to nhooyr/code-server that referenced this issue Jan 20, 2021
Any json or urlencoded request bodies were being consumed by body-parser
before they could be proxied. That's why requests without Content-Type
were proxied correctly as body-parser would not consume their body.

This allows the http-proxy package to passthrough the request body correctly
in all instances.

Closes coder#2377
nhooyr added a commit to nhooyr/code-server that referenced this issue Jan 20, 2021
@nhooyr
Copy link
Contributor

nhooyr commented Jan 20, 2021

Fix is at #2609

nhooyr added a commit that referenced this issue Feb 1, 2021
Any json or urlencoded request bodies were being consumed by body-parser
before they could be proxied. That's why requests without Content-Type
were proxied correctly as body-parser would not consume their body.

This allows the http-proxy package to passthrough the request body correctly
in all instances.

Closes #2377
nhooyr added a commit that referenced this issue Feb 1, 2021
Any json or urlencoded request bodies were being consumed by body-parser
before they could be proxied. That's why requests without Content-Type
were proxied correctly as body-parser would not consume their body.

This allows the http-proxy package to passthrough the request body correctly
in all instances.

Closes #2377
@nhooyr nhooyr closed this as completed Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants