ObjFW  Check-in [46881c3773]

Overview
Comment:OFHTTPRequest: Disallow redirects from HTTPS to HTTP by default.
Still works when setting redirectsFromHTTPSToHTTPAllowed.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 46881c3773a24122ae319e27ae720f6d85abd10a47ac2208568d519112838443
User & Date: js on 2011-03-30 00:36:27
Other Links: manifest | tags
Context
2011-03-30
17:43
A few minor improvements in configure.ac. check-in: df6f3a1895 user: js tags: trunk
00:36
OFHTTPRequest: Disallow redirects from HTTPS to HTTP by default.
Still works when setting redirectsFromHTTPSToHTTPAllowed.
check-in: 46881c3773 user: js tags: trunk
00:03
A few win32 fixes. check-in: 13a4dee1da user: js tags: trunk
Changes

Modified src/OFHTTPRequest.h from [ee98886554] to [3154174ff6].

33
34
35
36
37
38
39

40
41
42
43
44
45
46

47
48
49
50
51
52
53
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55







+







+







 */
@interface OFHTTPRequest: OFObject
{
	OFURL *URL;
	of_http_request_type_t requestType;
	OFString *queryString;
	OFDictionary *headers;
	BOOL redirectsFromHTTPSToHTTPAllowed;
}

#ifdef OF_HAVE_PROPERTIES
@property (copy) OFURL *URL;
@property (assign) of_http_request_type_t requestType;
@property (copy) OFString *queryString;
@property (copy) OFDictionary *headers;
@property (assign) BOOL redirectsFromHTTPSToHTTPAllowed;
#endif

/**
 * \return A new, autoreleased OFHTTPRequest
 */
+ request;

109
110
111
112
113
114
115












116
117
118
119
120
121
122
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136







+
+
+
+
+
+
+
+
+
+
+
+







- (void)setHeaders: (OFDictionary*)headers;

/**
 * \return A dictionary with headers for the HTTP request.
 */
- (OFDictionary*)headers;

/**
 * Sets whether redirects from HTTPS to HTTP are allowed.
 *
 * \param allowed Whether redirects from HTTPS to HTTP are allowed
 */
- (void)setRedirectsFromHTTPSToHTTPAllowed: (BOOL)allowed;

/**
 * \return Whether redirects from HTTPS to HTTP are allowed
 */
- (BOOL)redirectsFromHTTPSToHTTPAllowed;

/**
 * Performs the HTTP request and returns an OFHTTPRequestResult.
 *
 * \return An OFHTTPRequestResult with the result of the HTTP request
 */
- (OFHTTPRequestResult*)perform;

Modified src/OFHTTPRequest.m from [43e2c90ca2] to [5637b3f014].

117
118
119
120
121
122
123










124
125
126
127
128
129
130
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140







+
+
+
+
+
+
+
+
+
+







	OF_SETTER(headers, headers_, YES, YES)
}

- (OFDictionary*)headers
{
	OF_GETTER(headers, YES)
}

- (void)setRedirectsFromHTTPSToHTTPAllowed: (BOOL)allowed
{
	redirectsFromHTTPSToHTTPAllowed = allowed;
}

- (BOOL)redirectsFromHTTPSToHTTPAllowed
{
	return redirectsFromHTTPSToHTTPAllowed;
}

- (OFHTTPRequestResult*)perform
{
	return [self performWithRedirects: 10];
}

- (OFHTTPRequestResult*)performWithRedirects: (size_t)redirects
253
254
255
256
257
258
259
260

261
262




263
264
265
266
267
268
269
263
264
265
266
267
268
269

270
271

272
273
274
275
276
277
278
279
280
281
282







-
+

-
+
+
+
+








			do {
				tmp++;
			} while (*tmp == ' ');

			value = [OFString stringWithCString: tmp];

			if (redirects > 0 && (status == 301 || status == 302 ||
			if ((redirects > 0 && (status == 301 || status == 302 ||
			    status == 303) && [key caseInsensitiveCompare:
			    @"Location"] == OF_ORDERED_SAME) {
			    @"Location"] == OF_ORDERED_SAME) &&
			    (redirectsFromHTTPSToHTTPAllowed ||
			    [scheme isEqual: @"http"] ||
			    ![value hasPrefix: @"http://"])) {
				OFURL *new;

				new = [[OFURL alloc] initWithString: value
						      relativeToURL: URL];
				[URL release];
				URL = new;

Modified src/OFString.m from [0f0b8d53a9] to [f081783cbe].

712
713
714
715
716
717
718
719

720
721
722
723
724
725
726
727
712
713
714
715
716
717
718

719

720
721
722
723
724
725
726







-
+
-







	if ([[url scheme] isEqual: @"file"]) {
		self = [[c alloc] initWithContentsOfFile: [url path]
						encoding: encoding];
		[pool release];
		return self;
	}

	req = [OFHTTPRequest request];
	req = [OFHTTPRequest requestWithURL: url];
	[req setURL: url];
	res = [req perform];

	if ([res statusCode] != 200)
		@throw [OFHTTPRequestFailedException
		    newWithClass: [req class]
		     HTTPRequest: req
		      statusCode: [res statusCode]];