summaryrefslogtreecommitdiff
path: root/src/gmrequest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gmrequest.c')
-rw-r--r--src/gmrequest.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/gmrequest.c b/src/gmrequest.c
index 5ee3382c..fa7a39c9 100644
--- a/src/gmrequest.c
+++ b/src/gmrequest.c
@@ -7,7 +7,7 @@
7 7
8#include <SDL_timer.h> 8#include <SDL_timer.h>
9 9
10static const int BODY_TIMEOUT = 1500; /* ms */ 10static const int BODY_TIMEOUT = 3000; /* ms */
11 11
12enum iGmRequestState { 12enum iGmRequestState {
13 initialized_GmRequestState, 13 initialized_GmRequestState,
@@ -186,7 +186,7 @@ void submit_GmRequest(iGmRequest *d) {
186 clear_Block(&d->body); 186 clear_Block(&d->body);
187 iUrl url; 187 iUrl url;
188 init_Url(&url, &d->url); 188 init_Url(&url, &d->url);
189 if (!cmpCStrSc_Rangecc(&url.protocol, "file", &iCaseInsensitive)) { 189 if (equalCase_Rangecc(&url.protocol, "file")) {
190 iString *path = collect_String(urlDecode_String(collect_String(newRange_String(url.path)))); 190 iString *path = collect_String(urlDecode_String(collect_String(newRange_String(url.path))));
191 iFile * f = new_File(path); 191 iFile * f = new_File(path);
192 if (open_File(f, readOnly_FileMode)) { 192 if (open_File(f, readOnly_FileMode)) {
@@ -223,6 +223,35 @@ void submit_GmRequest(iGmRequest *d) {
223 iNotifyAudience(d, finished, GmRequestFinished); 223 iNotifyAudience(d, finished, GmRequestFinished);
224 return; 224 return;
225 } 225 }
226 else if (equalCase_Rangecc(&url.protocol, "data")) {
227 d->code = success_GmStatusCode;
228 iString *src = collectNewCStr_String(url.protocol.start + 5);
229 iRangecc header = { constBegin_String(src), constBegin_String(src) };
230 while (header.end < constEnd_String(src) && *header.end != ',') {
231 header.end++;
232 }
233 iBool isBase64 = iFalse;
234 setRange_String(&d->header, header);
235 /* Check what's in the header. */ {
236 iRangecc entry = iNullRange;
237 while (nextSplit_Rangecc(&header, ";", &entry)) {
238 if (equal_Rangecc(&entry, "base64")) {
239 isBase64 = iTrue;
240 }
241 }
242 }
243 remove_Block(&src->chars, 0, size_Range(&header) + 1);
244 if (isBase64) {
245 set_Block(&src->chars, collect_Block(base64Decode_Block(&src->chars)));
246 }
247 else {
248 set_String(src, collect_String(urlDecode_String(src)));
249 }
250 set_Block(&d->body, &src->chars);
251 d->state = finished_GmRequestState;
252 iNotifyAudience(d, finished, GmRequestFinished);
253 return;
254 }
226 d->state = receivingHeader_GmRequestState; 255 d->state = receivingHeader_GmRequestState;
227 d->req = new_TlsRequest(); 256 d->req = new_TlsRequest();
228 iConnect(TlsRequest, d->req, readyRead, d, readIncoming_GmRequest_); 257 iConnect(TlsRequest, d->req, readyRead, d, readIncoming_GmRequest_);