API  0.9.6
 All Classes Files Functions Variables Macros Groups Pages
CPURLRequest.j
Go to the documentation of this file.
1 /*
2  * CPURLRequest.j
3  * Foundation
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2008, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
32 @implementation CPURLRequest : CPObject
33 {
34  CPURL _URL;
35 
36  // FIXME: this should be CPData
37  CPString _HTTPBody;
38  CPString _HTTPMethod;
39  CPDictionary _HTTPHeaderFields;
40 }
41 
47 + (id)requestWithURL:(CPURL)aURL
48 {
49  return [[CPURLRequest alloc] initWithURL:aURL];
50 }
51 
55 - (id)init
56 {
57  return [self initWithURL:nil];
58 }
59 
66 - (id)initWithURL:(CPURL)aURL
67 {
68  self = [super init];
69 
70  if (self)
71  {
72  [self setURL:aURL];
73 
74  _HTTPBody = @"";
75  _HTTPMethod = @"GET";
76  _HTTPHeaderFields = [CPDictionary dictionary];
77 
78  [self setValue:"Thu, 01 Jan 1970 00:00:00 GMT" forHTTPHeaderField:"If-Modified-Since"];
79  [self setValue:"no-cache" forHTTPHeaderField:"Cache-Control"];
80  [self setValue:"XMLHttpRequest" forHTTPHeaderField:"X-Requested-With"];
81  }
82 
83  return self;
84 }
85 
89 - (CPURL)URL
90 {
91  return _URL;
92 }
93 
98 - (void)setURL:(CPURL)aURL
99 {
100  // Lenient and accept strings.
101  _URL = new CFURL(aURL);
102 }
103 
108 - (void)setHTTPBody:(CPString)anHTTPBody
109 {
110  _HTTPBody = anHTTPBody;
111 }
112 
116 - (CPString)HTTPBody
117 {
118  return _HTTPBody;
119 }
120 
125 - (void)setHTTPMethod:(CPString)anHTTPMethod
126 {
127  _HTTPMethod = anHTTPMethod;
128 }
129 
133 - (CPString)HTTPMethod
134 {
135  return _HTTPMethod;
136 }
137 
141 - (CPDictionary)allHTTPHeaderFields
142 {
143  return _HTTPHeaderFields;
144 }
145 
150 - (CPString)valueForHTTPHeaderField:(CPString)aField
151 {
152  return [_HTTPHeaderFields objectForKey:aField];
153 }
154 
160 - (void)setValue:(CPString)aValue forHTTPHeaderField:(CPString)aField
161 {
162  [_HTTPHeaderFields setObject:aValue forKey:aField];
163 }
164 
165 @end