Projects tigase _server server-core Issues #211
Content-Length header missing in response sent for a pre-flight OPTIONS request (CORS) while using BOSH (#211)
harsh upreti opened 1 decade ago

When my application running on chrome browser sends a pre-flight OPTIONS request before sending the POST to start the BOSH session, the server response to OPTIONS does not contain a Content-Length header. Although the response does not have any body and the Content length is 0, but despite this the response should contain the header Content-Length: 0

Because of the missing header the chrome's pre-flight request many a times remains in pending state.

Irrespective of this I think that every Http response should contain Content-Length.

A sample request response is as following:

OPTIONS / HTTP/1.1

Host: sample.im:5280

Connection: keep-alive

Access-Control-Request-Method: POST

Origin: http://stanzapper.appspot.com

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36

Access-Control-Request-Headers: origin, content-type

Accept: /

Referer: http://stanzapper.appspot.com/

Accept-Encoding: gzip,deflate,sdch

Accept-Language: en-US,en;q=0.8

HTTP/1.1 200 OK

Content-Type: text/xml; charset=utf-8

Access-Control-Allow-Origin: *

Access-Control-Allow-Methods: GET, POST, OPTIONS

Access-Control-Allow-Headers: Content-Type

Access-Control-Max-Age: 86400

Server: Tigase Bosh/3.3.0.0

The response should contain the Content-Length header, along with the headers copied from bosh-extra-headers.txt

I tried to correct this in my local source code of tigase by changing the method prepareHeaders in BoshIOService.java as such:

@

public StringBuilder prepareHeaders(String data) {

	StringBuilder sb = new StringBuilder(200);


	sb.append(HTTP_OK_RESPONSE);

	sb.append(CONTENT_TYPE_HEADER).append(content_type).append(EOL);

	if (data != null) {

		sb.append(CONTENT_TYPE_LENGTH).append(data.getBytes().length).append(EOL);

	}else{

		//else condition added by me

		sb.append(CONTENT_TYPE_LENGTH).append(0).append(EOL);

	}

	if (extra_headers != null) {

		sb.append(extra_headers);

	}

	sb.append(SERVER).append(EOL);

	sb.append(EOL);


	return sb;

}

@

the else is added by me, this seems to have taken care of the issue and BOSH works fine on chrome now.

Please fix this issue in the trunk of tigase as well.

Andrzej Wójcik (Tigase) commented 1 decade ago

Fix applied and verified.

Artur Hefczyc commented 1 decade ago

Thank you for the bug report and providing us with a resolution to the problem.

issue 1 of 1
Type
Bug
Priority
Normal
Assignee
RedmineID
1429
Version
tigase-server-5.2.0
Issue Votes (0)
Watchers (0)
Reference
tigase/_server/server-core#211
Please wait...
Page is in error, reload to recover