fix: cookies removed on failed connection - #5
Conversation
There was a problem hiding this comment.
Mostly some opinionated formatting changes here to improve readability. Can revert anything if preferred.
| OLD_IP_FILE=/tmp/MAM.ip | ||
| RESPONSE_FILE=/tmp/MAM.output | ||
| TEMP_COOKIE_FILE=/tmp/MAM.cookies | ||
| COOKIE_FILE=/config/MAM.cookies |
There was a problem hiding this comment.
Renamed variables to have more meaning. For example, there are multiple temporary, cached files, so CACHEFILE would be confusing. Also using SCREAMING_SNAKE_CASE since I find this easier to read instead of concatenating words together.
| echo "New IP detected" | ||
| # Save cookie jar to temporary file, to not overwrite | ||
| # with empty cookies on failed requests | ||
| curl -s -b $COOKIE_FILE -c $TEMP_COOKIE_FILE https://t.myanonamouse.net/json/dynamicSeedbox.php > $RESPONSE_FILE |
There was a problem hiding this comment.
This is the crux of the fix. When using the -c flag with curl, it writes all the cookies to the file passed here (even on failed requests, it will write empty cookies). Here's a relevant snippet from man curl:
-c, --cookie-jar <filename>
(HTTP) Specify to which file you want curl to write all cookies after a completed operation. curl writes
all cookies from its in-memory cookie storage to the given file at the end of operations. Even if no
cookies are known, a file is created so that it removes any formerly existing cookies from the file. The
file uses the Netscape cookie file format. If you set the filename to a single minus, "-", the cookies
are written to stdout.
| # Update COOKIE_FILE only on successful requests | ||
| mv $TEMP_COOKIE_FILE $COOKIE_FILE |
There was a problem hiding this comment.
Other relevant part of this fix. Everything else is formatting or variable name changes.
Fixes issue:
#2
Potentially fixes #1, but could not reproduce.
Made some formatting, readability changes as well, but can move to a separate PR if preferred.
So far this is working for me when building the image locally and dropping it in as a replacement in my compose file.
Superseded previous PR: #3