Differences From Artifact [f1713b1a20]:
- File
src/OFHTTPRequest.m
— part of check-in
[9ed387bacb]
at
2011-04-22 14:13:30
on branch trunk
— Add OFHTTPRequestDelegate.
This allows status updates etc. (user: js, size: 9190) [annotate] [blame] [check-ins using]
To Artifact [0e781dce42]:
- File
src/OFHTTPRequest.m
— part of check-in
[1cc6f3659f]
at
2011-04-22 14:35:13
on branch trunk
— OFHTTPRequest: Make it possible to not store the data in an OFDataArray.
This way, it's possible to do downloads without keeping the whole file
in memory. (user: js, size: 9433) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
54 55 56 57 58 59 60 61 62 63 64 65 66 67 | self = [super init]; requestType = OF_HTTP_REQUEST_TYPE_GET; headers = [[OFDictionary alloc] initWithObject: @"Something using ObjFW " @"<https://webkeks.org/objfw/>" forKey: @"User-Agent"]; return self; } - initWithURL: (OFURL*)url { self = [self init]; | > | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | self = [super init]; requestType = OF_HTTP_REQUEST_TYPE_GET; headers = [[OFDictionary alloc] initWithObject: @"Something using ObjFW " @"<https://webkeks.org/objfw/>" forKey: @"User-Agent"]; storesData = YES; return self; } - initWithURL: (OFURL*)url { self = [self init]; |
︙ | ︙ | |||
140 141 142 143 144 145 146 147 148 149 150 151 152 153 | OF_SETTER(delegate, delegate_, YES, NO) } - (id <OFHTTPRequestDelegate>)delegate { OF_GETTER(delegate, YES) } - (OFHTTPRequestResult*)perform { return [self performWithRedirects: 10]; } - (OFHTTPRequestResult*)performWithRedirects: (size_t)redirects | > > > > > > > > > > | 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | OF_SETTER(delegate, delegate_, YES, NO) } - (id <OFHTTPRequestDelegate>)delegate { OF_GETTER(delegate, YES) } - (void)setStoresData: (BOOL)enabled { storesData = enabled; } - (BOOL)storesData { return storesData; } - (OFHTTPRequestResult*)perform { return [self performWithRedirects: 10]; } - (OFHTTPRequestResult*)performWithRedirects: (size_t)redirects |
︙ | ︙ | |||
178 179 180 181 182 183 184 185 186 187 188 189 190 191 | OFMutableDictionary *s_headers; OFDataArray *data; OFEnumerator *enumerator; OFString *key; int status; const char *t = NULL; char *buf; [sock connectToHost: [URL host] onPort: [URL port]]; /* * Work around a bug with packet bisection in lighttpd when * using HTTPS. | > | 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | OFMutableDictionary *s_headers; OFDataArray *data; OFEnumerator *enumerator; OFString *key; int status; const char *t = NULL; char *buf; size_t bytesReceived; [sock connectToHost: [URL host] onPort: [URL port]]; /* * Work around a bug with packet bisection in lighttpd when * using HTTPS. |
︙ | ︙ | |||
323 324 325 326 327 328 329 | forKey: key]; } [delegate request: self didReceiveHeaders: s_headers withStatusCode: status]; | > | > > > > < < > > > > | | 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | forKey: key]; } [delegate request: self didReceiveHeaders: s_headers withStatusCode: status]; if (storesData) data = [OFDataArray dataArrayWithItemSize: 1]; else data = nil; buf = [self allocMemoryWithSize: of_pagesize]; bytesReceived = 0; @try { size_t len; while ((len = [sock readNBytes: of_pagesize intoBuffer: buf]) > 0) { [delegate request: self didReceiveData: buf withLength: len]; bytesReceived += len; [data addNItems: len fromCArray: buf]; } } @finally { [self freeMemory: buf]; } if ([s_headers objectForKey: @"Content-Length"] != nil) { intmax_t cl; cl = [[s_headers objectForKey: @"Content-Length"] decimalValue]; if (cl > SIZE_MAX) @throw [OFOutOfRangeException newWithClass: isa]; if (cl != bytesReceived) @throw [OFTruncatedDataException newWithClass: isa]; } /* * Class swizzle the dictionary to be immutable. We pass it as * OFDictionary*, so it can't be modified anyway. But not |
︙ | ︙ |