Eliminate an unnecessary HTTP request during login#288
Eliminate an unnecessary HTTP request during login#288madsmtm merged 1 commit intofbchat-dev:masterfrom
Conversation
This change eliminates requesting and downloading the entire FB home page (~160kb) every login.
|
I see this applies to logging in with session cookies. In a regular login the check is made here: # Sometimes Facebook tries to show the user a "Save Device" dialog
if 'save-device' in r.url:
r = self._cleanGet(self.req_url.SAVE_DEVICE)
if 'home' in r.url:If Facebook tries to show the user a "Save Device" dialog... doesn't that mean the log in was successful already? Is the followup request (2 requests actually, because of an HTTP redirect) necessary? |
|
I think the reason for making sure to pass the 'save-device' dialog was mostly just a hotfix, not really thought out. But maybe it also helped making sure that when we want to fetch the home page in Though that seems unlikely, and you're probably right in that it could be removed Though really should find another way to test if the user successfully logged in, since Facebook keep adding a bunch of alerts and such all the time, that will break our code. For example, I've seen a "Changes to match GDPR" alert recently, and I once saw a "Happy Birthday" alert, too. Maybe it's possible to just check if the |
|
Checking for the c_user does sound like a better approach. Regarding the concern of wanting to make sure to pass the 'save-device' dialog: because the previous request is made using |
|
Hmm, not exactly sure what you mean, are you saying that we already have in line 259, and that line 260 is unnecessary? But maybe we should just drop this discussion, and attempt to implement the Anyway, your recent PRs are definitely without a problem, I'll merge them, but probably only release a new version when we're done |
|
Thanks for merging them all so quickly! I'll be out for further developments for the time being, so feel free to tackle it yourself |
| r = self._cleanGet(self.req_url.LOGIN) | ||
| return 'home' in r.url | ||
| r = self._cleanGet(self.req_url.LOGIN, allow_redirects=False) | ||
| return 'home' in r.headers['Location'] |
There was a problem hiding this comment.
This fails if the Location header isn't set, as when the client isn't logged in, and therefore isn't redirected. I went ahead and fixed it with by testing if 'Location' in r.headers
This change eliminates requesting and downloading the entire FB home page (~160kb) every login.
Another HTTP request can be eliminated when logging in using session cookies by removing
or not self.isLoggedIn()from line 74 of client.py, because if the session_cookies are not valid,setSession()would surely return False, because of the many exceptions that_postLogin()will be throwing.What do you think?