![]() |
API 0.9.5
|
00001 /* 00002 * CPURLRequest.j 00003 * Foundation 00004 * 00005 * Created by Francisco Tolmasky. 00006 * Copyright 2008, 280 North, Inc. 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 00032 @implementation CPURLRequest : CPObject 00033 { 00034 CPURL _URL; 00035 00036 // FIXME: this should be CPData 00037 CPString _HTTPBody; 00038 CPString _HTTPMethod; 00039 CPDictionary _HTTPHeaderFields; 00040 } 00041 00047 + (id)requestWithURL:(CPURL)aURL 00048 { 00049 return [[CPURLRequest alloc] initWithURL:aURL]; 00050 } 00051 00057 - (id)initWithURL:(CPURL)aURL 00058 { 00059 self = [super init]; 00060 00061 if (self) 00062 { 00063 [self setURL:aURL]; 00064 00065 _HTTPBody = @""; 00066 _HTTPMethod = @"GET"; 00067 _HTTPHeaderFields = [CPDictionary dictionary]; 00068 00069 [self setValue:"Thu, 01 Jan 1970 00:00:00 GMT" forHTTPHeaderField:"If-Modified-Since"]; 00070 [self setValue:"no-cache" forHTTPHeaderField:"Cache-Control"]; 00071 [self setValue:"XMLHttpRequest" forHTTPHeaderField:"X-Requested-With"]; 00072 } 00073 00074 return self; 00075 } 00076 00080 - (CPURL)URL 00081 { 00082 return _URL; 00083 } 00084 00089 - (void)setURL:(CPURL)aURL 00090 { 00091 // Lenient and accept strings. 00092 _URL = new CFURL(aURL); 00093 } 00094 00099 - (void)setHTTPBody:(CPString)anHTTPBody 00100 { 00101 _HTTPBody = anHTTPBody; 00102 } 00103 00107 - (CPString)HTTPBody 00108 { 00109 return _HTTPBody; 00110 } 00111 00116 - (void)setHTTPMethod:(CPString)anHTTPMethod 00117 { 00118 _HTTPMethod = anHTTPMethod; 00119 } 00120 00124 - (CPString)HTTPMethod 00125 { 00126 return _HTTPMethod; 00127 } 00128 00132 - (CPDictionary)allHTTPHeaderFields 00133 { 00134 return _HTTPHeaderFields; 00135 } 00136 00141 - (CPString)valueForHTTPHeaderField:(CPString)aField 00142 { 00143 return [_HTTPHeaderFields objectForKey:aField]; 00144 } 00145 00151 - (void)setValue:(CPString)aValue forHTTPHeaderField:(CPString)aField 00152 { 00153 [_HTTPHeaderFields setObject:aValue forKey:aField]; 00154 } 00155 00156 @end