HUGE Progress
The past few hours I have worked on this project have been extremely productive. I found a header that genuine Google Docs sends, “X-Same-Domain”, which I believe just indicates whether the request is being sent to the same domain as the sender. It turns out that Google actively blocks requests from other domains, but luckily we can just send “X-Same-Domain” with a value of 1, pretending to be coming from the “docs.google.com” domain. After this realization the “/save” endpoint returned 200 (OK). This was huge progress, this has been a major blocker for months. The one problem was that while the status code stated that the request was successful, the actual request payload contained an error “XSRF” and a string of numbers and letters, which I thought was probably some kind of authentication/coordination token. After a quick Google search, I realized that this was a token to prevent other websites in the same browser from sending requests impersonating Google Docs as the browser auto attaches authentication cookies. To my surprise, when I added “&token=XXXXXX” (with XXXXXX being the string of numbers and letters) to the request url, we get a different error! This one was very ambiguous though, it just was a JSON payload containing nothing but the number “400”, as in 400 (Bad Request) which I had become to dread. After searching around the codebase for a while I found a problem with the url encoding logic, Url encoding is the proccess of replacing invalid character with %XX (XX being the ASCII code for the invalid character), it turns out “&“s are valid characters……. but I was replacing them. Ampersands are also the seperator for parameters. I think the problem was that within the Google Docs server code, it seperates the parameters then decodes each one. With this problem fixed, saving worked!!!! There were a few tiny bugs I wont get into, but largely it worked. I implemented merging changes(sending “hello” rather than “h” + “e” + “l”+ “l”+ “o”). With saving working, I decided to start working on seeing whether these solutions also worked on “/bind” (real-time incoming changes), they didn’t immediately, but after a few tweaks trying to replicate the URL parameters that Google Docs uses, we had incoming changes! I had to do some fancy async enumerable shenanigans to get them to come in asynchronously. The main thing left to do on incoming changes is to set up a seperate thread.
Anyhow, Big Devlog, just felt that if I wrote a devlog, it would be outdated within the hour.
See ya next time! ; )