Autochange dl.dropbox.com to dl.dropboxusercontent.com urls

This avoids a pointless 302 redirect, saves up to 200ms for people with sucky connections
This commit is contained in:
UnknownShadow200 2019-12-16 23:49:38 +11:00
parent c943e7ca33
commit b2c198b1a5

View File

@ -130,27 +130,44 @@ static volatile int http_curProgress = ASYNC_PROGRESS_NOTHING;
static void Http_DownloadNextAsync(void); static void Http_DownloadNextAsync(void);
#endif #endif
static const String urlRewrites[4] = {
String_FromConst("http://dl.dropbox.com/"), String_FromConst("https://dl.dropboxusercontent.com/"),
String_FromConst("https://dl.dropbox.com/"), String_FromConst("https://dl.dropboxusercontent.com/")
};
/* Converts say dl.dropbox.com/xyZ into dl.dropboxusercontent.com/xyz */
static void Http_GetUrl(const String* url, String* dst) {
String part;
int i;
for (i = 0; i < Array_Elems(urlRewrites); i += 2) {
if (!String_CaselessStarts(url, &urlRewrites[i])) continue;
part = String_UNSAFE_SubstringAt(url, urlRewrites[i].length);
String_Format2(dst, "%s%s", &urlRewrites[i + 1], &part);
return;
}
String_Copy(dst, url);
}
/* Adds a req to the list of pending requests, waking up worker thread if needed. */ /* Adds a req to the list of pending requests, waking up worker thread if needed. */
static void Http_Add(const String* url, cc_bool priority, const String* id, cc_uint8 type, const String* lastModified, const String* etag, const void* data, cc_uint32 size, struct EntryList* cookies) { static void Http_Add(const String* url, cc_bool priority, const String* id, cc_uint8 type, const String* lastModified, const String* etag, const void* data, cc_uint32 size, struct EntryList* cookies) {
struct HttpRequest req = { 0 }; struct HttpRequest req = { 0 };
String str; String str;
String_InitArray(str, req.URL); String_InitArray(str, req.URL);
String_Copy(&str, url); Http_GetUrl(url, &str);
Platform_Log2("Adding %s (type %b)", url, &type); Platform_Log2("Adding %s (type %b)", &str, &type);
String_InitArray(str, req.ID); String_CopyToRawArray(req.ID, id);
String_Copy(&str, id);
req.RequestType = type; req.RequestType = type;
if (lastModified) { if (lastModified) {
String_InitArray(str, req.LastModified); String_CopyToRawArray(req.LastModified, lastModified);
String_Copy(&str, lastModified);
} }
if (etag) { if (etag) {
String_InitArray(str, req.Etag); String_CopyToRawArray(req.Etag, etag);
String_Copy(&str, etag);
} }
if (data) { if (data) {