candy/strophe -- using prebind (.attach) results in tight idle loop? - xmpp

I'm using Candy.js (v1.7.1) and Openfire v3.9.3. Running the sample index.html included in the Candy package, I have no issues using direct authentication (browser prompts for jid/pwd). However, if I change the sample to use Candy.Core.attach (nearly a pass-thru to Strophe.Connection.attach) after performing a server side prebind (uisng MatriX), I seem to get stuck in some sort of idle loop that blasts empty messages to the XMPP server 3x a second.
Any ideas what is causing this looping and why the demo Candy UI doesn't appear when I use Candy.Core.attach?
Modified sample...
$(document).ready(function() {
var httpbindUrl = 'http://xmpp.mydomain.net:7070/http-bind/';
var chatRoom = 'testroom#conference.mydomain.net';
// These values come from a REST call to our services that perform
// the prebind authentication (using MatriX, obviously)
var jid = 'someuser#mydomain.net/MatriX';
var sid = 'b95ffa4'; // must be a string despite what candy's doc say
var rid = 1983626985;
Candy.init(httpbindUrl, {
core: {
debug: true,
autojoin: [chatRoom]
},
view: { assets: './res/' }
});
Candy.Core.attach(jid, sid, rid); // this seems to cause some sort of looping to occur
// Candy.Core.connect('someuser#mydomain.net', 'password'); // <-- this works as expected
});
The browser's console log displays...
POST http://xmpp.mydomain.net:7070/http-bind/ [HTTP/1.1 200 OK 895ms]
POST http://xmpp.mydomain.net:7070/http-bind/ [HTTP/1.1 200 OK 491ms]
POST http://xmpp.mydomain.net:7070/http-bind/ [HTTP/1.1 200 OK 483ms]
"RECV: <body xmlns='http://jabber.org/protocol/httpbind' ack='1983626985'/>" candy.bundle.js:159
"LIBS:<1>: no requests during idle cycle, sending blank request" libs.bundle.js:1192
"LIBS:<0>: request id 4.0 posting" libs.bundle.js:1192
"LIBS:<0>: request id 4.0 state changed to 1" libs.bundle.js:1192
"SENT: <body rid='1983626986' xmlns='http://jabber.org/protocol/httpbind' sid='b95ffa4'/>" candy.bundle.js:159
POST http://xmpp.mydomain.net:7070/http-bind/ [HTTP/1.1 200 OK 436ms]
"LIBS:<0>: request id 4.1 state changed to 2" libs.bundle.js:1192
"LIBS:<0>: request id 4.1 state changed to 3" libs.bundle.js:1192
"LIBS:<0>: request id 4.1 state changed to 4" libs.bundle.js:1192
"LIBS:<0>: removing request" libs.bundle.js:1192
"LIBS:<0>: _throttledRequestHandler called with 0 requests" libs.bundle.js:1192
"LIBS:<0>: request id 4 should now be removed" libs.bundle.js:1192
"LIBS:<0>: request id 4.1 got 200" libs.bundle.js:1192
"LIBS:<1>: _dataRecv called" libs.bundle.js:1192
"RECV: <body xmlns='http://jabber.org/protocol/httpbind' ack='1983626986'/>" candy.bundle.js:159
"LIBS:<1>: no requests during idle cycle, sending blank request" libs.bundle.js:1192
"LIBS:<0>: request id 5.0 posting" libs.bundle.js:1192
"LIBS:<0>: request id 5.0 state changed to 1" libs.bundle.js:1192
"SENT: <body rid='1983626987' xmlns='http://jabber.org/protocol/httpbind' sid='b95ffa4'/>" candy.bundle.js:159
...continues in a similar pattern until I close the browser window.
NOTE: Entries prepended with "LIBS:" are from strophe's low-level logging (level, msg). It should also be noted that the candy demo wraps strophe.js into a larger bundle called libs.bundle.js.

Normally when you connect to a BOSH connection manager you have the ability to set the wait attribute on your first stanza (session creation request).
XEP-0124 Session Creation Response
Default value used by Strophe and Candy is 60. Can you confirm the value which MatriX is using when establishing your BOSH session?
Ex:
<body content='text/xml; charset=utf-8'
from='user#example.com'
hold='1'
rid='1573741820'
to='example.com'
route='xmpp:example.com:9999'
wait='60'
xml:lang='en'
xmpp:version='1.0'
xmlns='http://jabber.org/protocol/httpbind'
xmlns:xmpp='urn:xmpp:xbosh'/>

It seems Openfire v3.9.3 BOSH implementation is 'quirky'. MatriX developers were able to work around the issue. As of MatriX v1.6.0.1 the scenario is resolved.

Related

Axios get request always returns a blank response

I launched my app on heroku.
And ever since all of my axios get request return a blank html.
axios.post(process.env.REACT_APP_baseServerurl + '/create/get-users')
axios.get(process.env.REACT_APP_baseServerurl + '/create/get-users')
the response i get is always blank.
request
response
but if i change the same request to a post it works fine.
The get request works fine when i try it on my localhost. But when i deploy it on heroku it returns blank.
router.post('/get-users', (req,res) => {
res.json("asdsadas")
})
router.route('/get-users').get((req,res) => {
res.json("yes")
})
the POST request works but GET request returns a 304.
The 304 HTTP Status code means that the resource has not been modified since the last get request. This indicates that the server thinks you already have a copy of up-to-date data. The Server makes this assumption by looking at the If-None-Match and If-Modified-Since in your request header. (https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_redirection)
These are the actions you could take:
Cache the data manually on your first successful request (if there is one, otherwise there must be an error in the usage of the If-None-Match and If-Modified-Since headers) and re-use the cached data if the server returns a 304 status code.
Disable the mechanism and live with the fact that you might request the same data the server already gave you.

What status code should server respond with when status of completed asynchronous DELETE operation is requested?

Assume server responds with 202 ACCEPTED to DELETE request and sets Location header to \status\1, where progress can be tracked. While the request is being processed, 200 OK is returned for GET \status\1 with some info in response body. What should server respond when deletion is done? Should it return 404 NOT FOUND or should it return some other code indicating deleting was finished and preserve old statuses?
If you have a separate endpoint for the 'status of the operation', I would probably expect that endpoint to always return 200 OK with more information.
404 returning from that endpoint doesn't tell me that the original DELETE has succeeded, but it tells me that the 'status itself' is removed.

Why is the browser satisfied with a response without content-length

Usually when I send a response to the browser I have to enter content-length in the http headers, otherwise the browser never stops loading (wait for more data)
But recently, I tested rust code:
let response = format!("HTTP/1.1 200 OK\r\n\r\n{}", contents);
stream.write(response.as_bytes()).unwrap();
The browser receives this without any problems, stops loading after receiving the response.(even though content-length is not specified in the response)
Can someone pls explain this?... What makes the browser satisfied with the response in this scenario (even though it does not contain: Content-length)
Content-length is optional as long as the connection is closed after the response is done. From RFC 7230 section 3.3.3 Message Body Length:
Otherwise, this is a response message without a declared message
body length, so the message body length is determined by the
number of octets received prior to the server closing the
connection.

Zend setRawHeader

I have IndexController. I need to set raw header in indexAction.
I try to make
function indexAction(){
$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
}
But I see in Google chrome status 200 OK.
How set raw header?
To set a 404, use:
$this->getResponse()->setHttpResponseCode(404)
->setRawHeader('HTTP/1.1 404 Not Found'); // optional
If you don't explicitly set an HTTP response code, ZF will automatically send a 200 response if it was not overridden by setHttpResponseCode. Once it sends all the headers it checks to see if a response code was sent, and if not, sends a 200 regardless of your rawHeader.

Openfire prebind + robbiehanson/XMPPFramework using BOSH not working

We're trying to implement XMPP over BOSH for our product. The Strophe.js javascript library works fine for our needs on the WWW site. We request a prebind, it's delivered and then we use Strophe's 'attach' method to start our session - then we're able to update presence and send/receive messages. On the iOS side of things, we're using the robbiehanson XMPPFramework which includes a BOSH transport, but there's no attach method. Below is some of my grief with trying to get this to work.
I prebind, get my sid/jid/rid, then set the internal logic inside the bosh transport and other files to say that we're already connected. Then if I try to update presence, including the given SID, I send:
BOSH: SEND[1248340729] = < body xmlns="http://jabber.org/protocol/httpbind" sid="568a3ae9" ack="1248340728" rid="1248340729">< presence>< /presence>< /body>
but don't get any reply atall. That's the last of it. If I try to update presence without specifying SID, I send:
BOSH: SEND[1064338700] = < body xmlns="http://jabber.org/protocol/httpbind" ack="1064338699" rid="1064338700">< presence>< /presence>< /body>
and get back:
BOSH: RECD[1342811427] = < body xmlns="http://jabber.org/protocol/httpbind" xmlns:stream="http://etherx.jabber.org/streams" authid="9ef0ccdb" sid="9ef0ccdb" secure="true" requests="2" inactivity="300" polling="5" wait="60">< stream:features>< mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"> < mechanism>PLAIN< /mechanism>< /mechanisms>< compression xmlns="http://jabber.org/features/compress">< method>zlib< /method>< /compression>< bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/>< session xmlns="urn:ietf:params:xml:ns:xmpp-session"/>< /stream:features>< /body>
which looks like a connection affirmation, or a connection challenge stanza expecting me to respond with the PLAIN information - but this has already been established with the prebind. If it is a connection affirmation, then the next lines don't make sense. If using the SID provided by the connection string above, as if it's an affirmation (I'm not sure), these are the next lines:
BOSH: SEND[1342811427] = < body xmlns="http://jabber.org/protocol/httpbind" sid="9ef0ccdb" rid="1342811428">< iq type="set">< bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">< resource>api< /resource>< /bind>< /iq>< /body>
BOSH: RECD[1342811427] = < body xmlns='http://jabber.org/protocol/httpbind'>< iq xmlns="jabber:client" type="error" to="chat.*.com/9ef0ccdb">< bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">< resource>api< /resource>< /bind>< error code="401" type="auth">< not-authorized xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>< /error>< /iq>< /body>
I'm not authorized. Now if I try using the SID that was negotiated during prebind, the last two lines are different:
BOSH: SEND[1172064714] = < body xmlns="http://jabber.org/protocol/httpbind" sid="27e3745b" rid="1172064715">< iq type="set">< resource>api< /resource>< /bind>< /iq>< /body>
BOSH: RECD[1172064714] = < body xmlns="http://jabber.org/protocol/httpbind">< /body>
an empty response. Then if I try updating my presence again, it gives me a literal 404 page saying there's an invalid SID. When I was using the SID provided by openfire, if I re-tried the presence update, it would just keep on giving me 401 not authorized.
Any help would be greatly appreciated.