The My Opera forums have been replaced with forums.opera.com. Please head over there to discuss Opera's products and features

See the new Forums

XMLHttpRequest to Opera Link (link.api.opera.com) gives Bad Request in Firefox

Forums » My Opera » My Opera: Feedback, questions and discussions

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

15. October 2011, 12:42:33

aykevl93

Posts: 3

XMLHttpRequest to Opera Link (link.api.opera.com) gives Bad Request in Firefox

Hello!
I am writing an extension to synchronize bookmarks with Chrome, Firefox and Opera. I currently use Google Bookmarks and Opera Link. Opera Link works in Chrome, but not in Firefox (Firefox gives a 400 Bad Request). The code is the same, so that shouldn't be the problem. I think the problem lies with the difference in headers:

Firefox:
POST /rest/bookmark/ HTTP/1.1
Host: localhost:8123
User-Agent: Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:8.0) Gecko/20100101 Firefox/8.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Authorization: OAuth realm="",oauth_consumer_key="immqSD074yPY83JWSKAzmjUUpOcC7u40",oauth_token="AT3dpXXXXX",oauth_version="1.0",oauth_timestamp="1318679723",oauth_nonce="A4XXXXX",oauth_signature_method="HMAC-SHA1",oauth_signature="F8IItHXXXXXXXXXXXXXXXX"
Content-Type: application/json; charset=UTF-8
Content-Length: 96
Pragma: no-cache
Cache-Control: no-cache

Chrome (Chromium) (I know it doesn't have the POST header):
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4,eo;q=0.2
Authorization:OAuth realm="",oauth_consumer_key="immqSD074yPY83JWSKAzmjUUpOcC7u40",oauth_token="ATI5XXXXXXXXXXXXXXXXXX",oauth_version="1.0",oauth_timestamp="1318679566",oauth_nonce="IcJXXXX",oauth_signature_method="HMAC-SHA1",oauth_signature="cNYXXXXXXXXXXXXXXXXXX"
Connection:keep-alive
Content-Length:90
Content-Type:application/json
Cookie:__kti=1304508457014,http%3A%2F%2Fwww.opera.com%2Fdocs%2Fapis%2Flinkrest%2F,; __ktv=9eb6-27f0-58c0-4d112fbac36039; language=en; __utma=122269525.1612809356.1304508454.1309807876.1318593402.12; __utmz=122269525.1318593402.12.5.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=opera%20link%20bad%20request
Host:link.api.opera.com
Origin:chrome-extension://dbbmibbibfblebmomaphijkkpbhfoemj
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Ubuntu/11.10 Chromium/14.0.835.202 Chrome/14.0.835.202 Safari/535.1

I think that the problem is that Chrome just uses the Content-Type:application/json header, and that firefox appends '; charset=UTF-8' at the end of the Content-Type (which Opera Link should understand, according to http://forums.mozillazine.org/viewtopic.php?p=6318215#p6318215). So, am I right and handles the Opera Link server the Content-Type header in a wrong way, or is there another problem?

I use a test account (it's much easier to just test a few bookmarks and not the whole list in my real account, and I don't want to mess up my bookmarks): test-vantester.

Another note: authorizing and getting bookmarks works just fine. Only POST requests don't work.

EDIT: it's indeed the appended charset that gives the error. I tested it in Chrome. When I appended '; charset=UTF-8' the server gives a Bad Request (which it shouldn't).

28. October 2011, 14:37:32

aykevl93

Posts: 3

*bump*

If my question wasn't clear: can this be fixed in Opera Link or is there a workaround?

18. December 2011, 12:31:57

aykevl93

Posts: 3

Well, I found a solution for this. When using xhr.sendAsBinary, Firefox doesn't send the charset option. But it only accepts Ascii data, other data will be escaped. So I also have to escape the data. See https://github.com/aykevl93/Sync2all/blob/master/chrome/content/operalink.js#L288
The main page of the extension is here: https://github.com/aykevl93/Sync2all
It works best on Chrome and also mostly on Firefox.

Forums » My Opera » My Opera: Feedback, questions and discussions