︙ | | | ︙ | |
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#include <string.h>
#import "OFHTTPRequest.h"
#import "OFString.h"
#import "OFURL.h"
#import "OFTCPSocket.h"
#import "OFDictionary.h"
#import "OFAutoreleasePool.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"
|
>
>
>
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#define OF_HTTP_REQUEST_M
#include <string.h>
#import "OFHTTPRequest.h"
#import "OFString.h"
#import "OFURL.h"
#import "OFTCPSocket.h"
#import "OFDictionary.h"
#import "OFDataArray.h"
#import "OFAutoreleasePool.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"
|
︙ | | | ︙ | |
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
redirectsFromHTTPSToHTTPAllowed = allowed;
}
- (BOOL)redirectsFromHTTPSToHTTPAllowed
{
return redirectsFromHTTPSToHTTPAllowed;
}
- (OFHTTPRequestResult*)perform
{
return [self performWithRedirects: 10];
}
- (OFHTTPRequestResult*)performWithRedirects: (size_t)redirects
|
>
>
>
>
>
>
>
>
>
>
|
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
redirectsFromHTTPSToHTTPAllowed = allowed;
}
- (BOOL)redirectsFromHTTPSToHTTPAllowed
{
return redirectsFromHTTPSToHTTPAllowed;
}
- (void)setDelegate: (id <OFHTTPRequestDelegate>)delegate_
{
OF_SETTER(delegate, delegate_, YES, NO)
}
- (id <OFHTTPRequestDelegate>)delegate
{
OF_GETTER(delegate, YES)
}
- (OFHTTPRequestResult*)perform
{
return [self performWithRedirects: 10];
}
- (OFHTTPRequestResult*)performWithRedirects: (size_t)redirects
|
︙ | | | ︙ | |
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
OFString *line, *path;
OFMutableDictionary *s_headers;
OFDataArray *data;
OFEnumerator *enumerator;
OFString *key;
int status;
const char *t = NULL;
[sock connectToHost: [URL host]
onPort: [URL port]];
/*
* Work around a bug with packet bisection in lighttpd when
* using HTTPS.
|
>
|
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
OFString *line, *path;
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.
|
︙ | | | ︙ | |
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
if ((redirects > 0 && (status == 301 || status == 302 ||
status == 303) && [key caseInsensitiveCompare:
@"Location"] == OF_ORDERED_SAME) &&
(redirectsFromHTTPSToHTTPAllowed ||
[scheme isEqual: @"http"] ||
![value hasPrefix: @"http://"])) {
OFURL *new;
new = [[OFURL alloc] initWithString: value
relativeToURL: URL];
[URL release];
URL = new;
if (status == 303) {
requestType = OF_HTTP_REQUEST_TYPE_GET;
[queryString release];
queryString = nil;
}
[pool release];
pool = nil;
return [self performWithRedirects:
redirects - 1];
}
[s_headers setObject: value
forKey: key];
}
data = [sock readDataArrayTillEndOfStream];
if ([s_headers objectForKey: @"Content-Length"] != nil) {
intmax_t cl;
cl = [[s_headers objectForKey: @"Content-Length"]
decimalValue];
|
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
if ((redirects > 0 && (status == 301 || status == 302 ||
status == 303) && [key caseInsensitiveCompare:
@"Location"] == OF_ORDERED_SAME) &&
(redirectsFromHTTPSToHTTPAllowed ||
[scheme isEqual: @"http"] ||
![value hasPrefix: @"http://"])) {
OFURL *new;
BOOL follow;
new = [OFURL URLWithString: value
relativeToURL: URL];
follow = [delegate request: self
willFollowRedirectTo: new];
if (!follow && delegate != nil) {
[s_headers setObject: value
forKey: key];
continue;
}
new = [new retain];
[URL release];
URL = new;
if (status == 303) {
requestType = OF_HTTP_REQUEST_TYPE_GET;
[queryString release];
queryString = nil;
}
[pool release];
pool = nil;
return [self performWithRedirects:
redirects - 1];
}
[s_headers setObject: value
forKey: key];
}
[delegate request: self
didReceiveHeaders: s_headers
withStatusCode: status];
data = [OFDataArray dataArrayWithItemSize: 1];
buf = [self allocMemoryWithSize: of_pagesize];
@try {
size_t len;
while ((len = [sock readNBytes: of_pagesize
intoBuffer: buf]) > 0) {
[data addNItems: len
fromCArray: buf];
[delegate request: self
didReceiveData: buf
withLength: len];
}
} @finally {
[self freeMemory: buf];
}
if ([s_headers objectForKey: @"Content-Length"] != nil) {
intmax_t cl;
cl = [[s_headers objectForKey: @"Content-Length"]
decimalValue];
|
︙ | | | ︙ | |
367
368
369
370
371
372
373
|
}
- (OFDataArray*)data
{
return [[data retain] autorelease];
}
@end
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
}
- (OFDataArray*)data
{
return [[data retain] autorelease];
}
@end
@implementation OFObject (OFHTTPRequestDelegate)
- (void)request: (OFHTTPRequest*)request
didReceiveHeaders: (OFDictionary*)headers
withStatusCode: (int)statusCode
{
}
- (void)request: (OFHTTPRequest*)request
didReceiveData: (const char*)data
withLength: (size_t)len
{
}
- (BOOL)request: (OFHTTPRequest*)request
willFollowRedirectTo: (OFURL*)url
{
return YES;
}
@end
|