Ktor client connection refused on localhost - ktor

I have a server listening on http://localhost:5173.
When I request from that server in Ktor client, it errors with Connection refused: no further information.
val client = HttpClient(CIO)
val response: HttpResponse = client.get("http://localhost:5173")

Ktor client seems to be rewriting localhost to 127.0.0.1 so getting the server to listen on 127.0.0.1 instead seems to fix it.

Related

An existing connection was forcibly closed by the remote host (net::ERR_HTTP2_PROTOCOL_ERROR)

I have unique apache http server which deliver html/css/js ressources for all clients.
each client access to his private account with subdomain
client-1.myurl.com
client-2.myurl.com
And I use mod_macro with ProxyPass to map request of a subdomain url to an external ip server:
by example
https://pastebin.com/Xp8ydjZD
But sometimes i got net::ERR_HTTP2_PROTOCOL_ERROR in my console while navigating on my website and a lot 503 errors, here is my apache log error file : https://pastebin.com/PjU7D3Py
Various error in apache log :
An existing connection was forcibly closed by the remote host. ...
AH01102: error reading status line from remote server at.myurl.com:8082, referer: https://at.myurl....
No connection could be made because the target machine actively refused it. : AH00957: HTTPS: attempt to connect to zzz.zz.zzz.zz:8082 (ij.myurl.com) failed....
AH01114: HTTP: failed to make connection to backend: ij.myurl.com, referer:...
Screenshot

How to setup secure tunnel to allow a client to communicate to a websocket?

I need to allow client to connect to a websocket on server 10.0.4.160. The 10.0.4.160 server does not have SSL installed on it but it have a websocket that is running on port 8080.
I need to setup a secure tunnel to allow the client to connect to the websocket.
I installed the stunnel on my windows Server 2008 R2, And changed my stunnel.conf file to look loke this
[websockets]
accept = 8443
connect = 8080
verify = 2
CAfile = ca-certs.pem
client = yes
I am expecting to connect to the server on port 8433 and the stunnel will allow the connection to connect to port 8080
This is the code that I use in the client's console "Of course, the console is on a PC that is on my internal network"
var conn = new WebSocket('wss://10.0.4.160:8443');
conn.onopen = function(e) {
console.log("Connection established!");
};
conn.onmessage = function(e) {
console.log(e.data);
};
While on the server I open up a command line and I execute this
telnet localhost 8080
I get a command line and when I fire the code above from a console I see this in the server's command line
But few seconds later I get this error in the console
WebSocket connection to 'wss://10.0.4.160:8443/' failed: Error in connection establishment: net::ERR_TIMED_OUT
If I try to send a command using conn.sent('Hello') I get this error
VM289:2 Uncaught DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
at Error (native)
at <anonymous>:2:6
at Object.InjectedScript._evaluateOn (<anonymous>:905:140)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:838:34)
at Object.InjectedScript.evaluate (<anonymous>:694:21)
Additionally, I tried to turn on debugging in strunnel by adding debug = 7
This is what I got in the stunnel console. I don't understand what is wrong as the logs show that the client is connected but I can't send messages from the client to the server
2015.08.16 16:40:06 LOG7[36]: Service [websockets] started
2015.08.16 16:40:06 LOG5[36]: Service [websockets] accepted connection from 10.0.4.195:21963
2015.08.16 16:40:06 LOG6[36]: s_connect: connecting 127.0.0.1:8080
2015.08.16 16:40:06 LOG7[36]: s_connect: s_poll_wait 127.0.0.1:8080: waiting 10 seconds
2015.08.16 16:40:06 LOG5[36]: s_connect: connected 127.0.0.1:8080
2015.08.16 16:40:06 LOG5[36]: Service [websockets] connected remote server from 127.0.0.1:50891
2015.08.16 16:40:06 LOG7[36]: Remote socket (FD=668) initialized
2015.08.16 16:40:06 LOG6[36]: SNI: sending servername: localhost
2015.08.16 16:40:06 LOG7[36]: SSL state (connect): before/connect initialization
2015.08.16 16:40:06 LOG7[36]: SSL state (connect): SSLv2/v3 write client hello A
What am I doing wrong here?
How come the connection keeps failing?

What is 502 Proxy error? How to Resolve it

When i try to login into Artifactory web appliaction ,its showing proxy error. The Error message is below.
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request POST /artifactory/webapp/login.html.
Reason: Error reading from remote server
Apache/2.2.15 (CentOS) Server at XX.XX.XX.XX Port 80
Any Solution for this?

When does the browser, e.g., FF, send a CONNET method instead of client hello?

In HTTP CONNECT tunneling (see http://en.wikipedia.org/wiki/HTTP_tunnel for reference), the client/browser sends a CONNET method request instead of a client hello as in the direct https connection.
My question is can I force the browser to still send client hello if I put a simple port forwarder between the client and the destination server? Or what makes a browser know that it should send a CONNECT method request other than client hello when there is a HTTP proxy between?
sends a CONNET method request instead of a client hello
No. It first sends the CONNECT to let the proxy built a tunnel to the original server. Once the tunnel is established the normal SSL Handshake is done, i.e.
With CONNECT (i.e. proxy)
--- connect to proxy
>> CONNECT sslhost:port HTTP/1.0
<< HTTP/1.0 200 Connection established
--- everything from now own is transferred by the proxy to/from the target host
>> SSLClientHello
<< SSLServerHello
....
without CONNECT (no proxy)
--- direct connection to sslhost:port
>> SSLClientHello
<< SSLServerHello
....

FTP client connection to HTTP server

I have implemented APACHE Mina server to connect to my local FTP client i.e. Command prompt, which is working fine. Now I want to send this FTP request i.e. FTP commands to an http proxy server (Apache http server) as an http request which will further connect to an FTP server.
I have used Apache common net FTPHTTP client class but I don't know how to implement the whole logic. Any link or example will be helpful.
My code is as follow:s
FTPClient ftpclient = new FTPHTTPClient("HTTPProxy",int port); //connecting to Apache HTTP server
boolean status = ftpclient.isConnected //This is returning me false
ftpclient.connect("FTPserver",int port); //connecting to FTP server
ftpclient.login("userId","userPassword"); //Login into FTP server
status = ftpclient.isConnected //This is returning me true
Is this connection is is an HTTP connection i.e. Http tunneling via Connect Http method ?
my exact requirement is :-
Ftp client <---> Ftp local server <----> Http server <---> Ftp server