URLSessionWebSocketTask fails with invalid response for specific service

324 views Asked by At

I'm currently trying to establish a websocket connection to a Paperless-ngx instance in iOS using URLSessions webSocketTask using the following code:

let wsTask = URLSession.shared.webSocketTask(with: URL(string: "wss://demo.paperparrot.me/ws/status/")!)
wsTask.resume()

This fails with the following:

Task <402E47F3-1EE4-4FE3-A36B-2BA7F6DAB26A>.<14> finished with error [-1011] Error Domain=NSURLErrorDomain Code=-1011 "Invalid server response." UserInfo={NSErrorFailingURLStringKey=https://demo.paperparrot.me/ws/status/, NSErrorFailingURLKey=https://demo.paperparrot.me/ws/status/, _NSURLErrorWebSocketHandshakeFailureReasonKey=0, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalWebSocketTask <402E47F3-1EE4-4FE3-A36B-2BA7F6DAB26A>.<14>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalWebSocketTask <402E47F3-1EE4-4FE3-A36B-2BA7F6DAB26A>.<14>, NSLocalizedDescription=Invalid server response.}

The curious thing is that, using the same code, I am able to connect to other websockets. The websockets for wss://demo.paperparrot.me also work in my browser or using any websocket tool.

NGINX only logs the following for request with the iOS example:

GET /ws/status/ HTTP/1.1" 403 0

While working connections log as

GET / HTTP/1.1" 500 21
GET /ws/status/ HTTP/1.1" 101 2

Am I missing something here?

0

There are 0 answers