drewzboto / grunt-connect-proxy

Grunt Connect support for proxying API calls during development
MIT License
424 stars 122 forks source link

Getting 400 Bad request: "You're speaking plain HTTP to an SSL-enabled server port." error. #79

Open Siim opened 9 years ago

Siim commented 9 years ago

Hi!

I have some configuration issues on OSX Mavericks: if I try to proxy some requests to https server then I get 400 Bad request. Here is the full message:

Bad Request

Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.

I thought that if I set https option to true then the proxy will handle it. I also configured the client app server to use SSL connection and even this will result the same error:

Here is my configuration:

module.exports = {
    nodePort: 3000,
    dataSource: 'proxy', 
    proxy: {
        proxies: [
            {
                context: '/test',
                host: 'localserver.lan',
                port: 443,
                https: true,
                changeOrigin: false
            }
        ]
    }
};
Skinner927 commented 9 years ago

+1

Same issue

Roll back to 0.1.10 which doesn't have this issue.

gazoakley commented 9 years ago

+1

Can also confirm this is a regression from 0.1.10

jan-pieter commented 9 years ago

+1

Also a problem on Ubuntu 14.04; 0.1.10 works as expected.

uxtracer commented 9 years ago

+1

omanizer commented 9 years ago

+1

pschyska commented 9 years ago

I'm also affected by this, can't rollback to 0.1.10 because then my wss proxy doesn't work. I found this line https://github.com/drewzboto/grunt-connect-proxy/blob/master/tasks/connect_proxy.js#L53 and the next to be a bit odd. The target should have a protocol, and secure is only about certificate validation (in the case you want to mitm the https). Maybe this changed from previous versions of http-proxy, but I think for HTTP->HTTPS proxying you only need to have a https:// target.

SeyZ commented 9 years ago

+1

aurelin commented 9 years ago

+1 Reverted to 0.1.10 - no issues there.

On Ubuntu 14.04.

micah-williamson commented 9 years ago

Has anyone forked and fixed this issue?

Stratus3D commented 9 years ago

+1

micah-williamson commented 9 years ago

The dude made a new version 14 days ago (after almost a year) and didn't fix this?

ruiaraujo commented 9 years ago

@iamchairs Feel free to send in a PR.

The new version was to fix people build which were broken.

callmeberzerker commented 9 years ago

When will this be addressed?

micah-williamson commented 9 years ago

@SpearThruster This was mentioned October 14th. I'm guessing it won't be. We've moved to gulp and no longer have these problems.

minznerjosh commented 9 years ago

I dug through the source code and found a simple fix:

To your proxy configuration, add protocol: 'https:'. I think I'll send a PR documenting this configuration option.

kofalt commented 8 years ago

Just ran into this, lost a half-hour before finding @minznerjosh's workaround. Works great, much appreciated.

@drewzboto Thoughts on the workaround above? Can we get this fixed? I am available to provide any additional details as desired.

mrDarcyMurphy commented 8 years ago

Looking through the changes between v0.2.0 and v0.1.10 I found this line:

server: httpProxy.createProxyServer({
  // ...
  secure: proxyOption.https
  // ...
})

In short, I got http => https proxying to work by setting my config like so:

{
  https: false,
  protocol: 'https:'
}

Doing it that way let me proxy my UI's api requests from http://localhost:9000/api to my api at https://localhost:8443/api. I hope that helps someone else.

amir-rahnama commented 8 years ago

:+1: on this! seriously, it sucks!

majster commented 8 years ago

Using "grunt-connect-proxy": "0.2.0", was getting The plain HTTP request was sent to HTTPS port while proxying to https.

{
  https: false,
  protocol: 'https:'
}

Did the job for me.

Frank683 commented 8 years ago

+1 Could this please be fixed or at least be document??

Thanks @minznerjosh @mrDarcyMurphy for the solution!

MishraSachin commented 7 years ago

same issue. while generating let'sencrypt certificate for my domain. How to solve this?