Is there a way for Mongoose to automatically redirect an HTTP requests to a HTTPS request?

1,427 views
Skip to first unread message

rick_...@yahoo.com

unread,
Jan 11, 2013, 11:38:46 AM1/11/13
to mongoos...@googlegroups.com
I am using Mongoose to process HTTP requests on port 80 and HTTPS requests on port 443. Is there a way for me to configure or modify Mongoose to automatically redirect HTTP requests to HTTPS?

Sergey Lyubka

unread,
Jan 11, 2013, 5:49:53 PM1/11/13
to mongoos...@googlegroups.com
You'd need two instances of mongoose.
First instance would listen on HTTP and redirect all requests to the second instance.
Simple CGI can do that.

On Fri, Jan 11, 2013 at 4:38 PM, <rick_...@yahoo.com> wrote:
process


jeff shanab

unread,
Jan 11, 2013, 5:53:28 PM1/11/13
to mongoos...@googlegroups.com
In an older copy of mongoose I think I listened on both http and https then on parseing the url I sent back one that had https.
Server was embedded, no access to file system at all. all urls handled in a handlers.cpp

--
You received this message because you are subscribed to the Google Groups "mongoose-users" group.
To post to this group, send email to mongoos...@googlegroups.com.
To unsubscribe from this group, send email to mongoose-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongoose-users?hl=en.

Sergey Lyubka

unread,
Jan 11, 2013, 5:54:11 PM1/11/13
to mongoos...@googlegroups.com
Yeah, with embedded code, it is easy to do with one instance.

On Fri, Jan 11, 2013 at 10:53 PM, jeff shanab <jsha...@gmail.com> wrote:
system


jeff shanab

unread,
Jan 11, 2013, 5:56:05 PM1/11/13
to mongoos...@googlegroups.com
Note, I am on the older mongoose. I did not make the upgrade to the new mongoose which no longer has the handlers.cpp because I have so much code based on that
 and it would be a painful refactor ATM.

rick_...@yahoo.com

unread,
Jan 14, 2013, 10:05:52 AM1/14/13
to mongoos...@googlegroups.com
Thanks for the responses. I went with the 2 instances and have that working

Sergey Lyubka

unread,
Jan 20, 2013, 5:24:12 AM1/20/13
to mongoos...@googlegroups.com
Update on this:
Latest mongoose now supports "r" specifier for the listening port.
It redirects the request to the first SSL port if it SSL is present, otherwise
request will be served from the HTTP port. For example:

mongoose -p 80r,443s -s cert.pem

This way you can get away with only one instance of mongoose.


--
You received this message because you are subscribed to the Google Groups "mongoose-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongoose-users/-/34tpeQiOIPcJ.

Charmet Laurent

unread,
Jan 22, 2013, 8:38:33 AM1/22/13
to mongoos...@googlegroups.com
Nice !

Is it possible to do this with only one port instead of 2 ?
In fact if I bind port 1234 and want only HTTPS, it will be very cool if incomming HTTP will be relocated to HTTPS

So does this syntax works ?

mongoose -p 1234r,1234s -s cert.pem

Charmet Laurent

unread,
Jan 22, 2013, 8:44:44 AM1/22/13
to mongoos...@googlegroups.com
Better to test by myself :-)


mongoose -p 1234r,1234s -s cert.pem
set_ports_option: cannot bind to 1234s: Address already in use

So it's appear to be not possible (or perhaps it exist another syntax to deal with it)

Regards,

Laurent

Sergey Lyubka

unread,
Jan 22, 2013, 9:51:30 AM1/22/13
to mongoos...@googlegroups.com
The problem is that HTTPS port expects SSL handshake data. It gets confused
if it gets "GET /...." instead of handshake bytes. I am not sure it is possible to
read the request first, then feed it back to SSL code.

Check http://google.com:443/ for example - it just fails, cause HTTPS is expecting a handshake.

--
You received this message because you are subscribed to the Google Groups "mongoose-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongoose-users/-/jm6y50VCT9cJ.

Charmet Laurent

unread,
Jan 22, 2013, 11:31:42 AM1/22/13
to mongoos...@googlegroups.com
With the help of the debugger, I see that SSL_read eats too many bytes to preserve the url, so it's not possible to send an 301 HTTP code + "Location" field in the response .
Adding a bufferization or a kind of proxy, is probably too risky, just for this special feature. And probably it's not working if the client is using HTTPS.

So forget my request, even if it's not user friendly to have no error when a user forgot to use https, but it concern HTTP protocole, not mongoose ;-)

Regards,

Laurent

Sergey Lyubka

unread,
Jan 22, 2013, 12:13:44 PM1/22/13
to mongoos...@googlegroups.com
Well it would be nice to have such redirect, it would save some
confusion. I'll take a look, maybe it is possible to do it with little cost.

On Tue, Jan 22, 2013 at 4:31 PM, Charmet Laurent <laurent...@gmail.com> wrote:
concern


Reply all
Reply to author
Forward
0 new messages