API  0.9.10
CPURLResponse.j
Go to the documentation of this file.
1 /*
2  * CPURLResponse.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 
24 /*
25  CPURL _URL;
26  CPString _MIMEType;
27  unsigned _expectedContentLength;
28  CPString _textEncodingName;
29 */
36 @implementation CPURLResponse : CPObject
37 {
38  CPURL _URL;
39 }
40 
41 - (id)initWithURL:(CPURL)aURL
42 {
43  self = [super init];
44 
45  if (self)
46  _URL = aURL;
47 
48  return self;
49 }
50 
52 {
53  return _URL;
54 }
55 /*
56 Creating a Response
57 initWithURL:MIMEType:expectedContentLength:textEncodingName:
58 Getting the Response Properties
59 expectedContentLength
60 suggestedFilename
61 MIMEType
62 textEncodingName
63 URL
64 */
65 @end
66 
70 @implementation CPHTTPURLResponse : CPURLResponse
71 {
72  int _statusCode;
73  CPString _allResponseHeaders;
74  CPDictionary _responseHeaders;
75 }
76 
77 + (CPDictionary)parseHTTPHeaders:(CPString)headersString
78 {
80 
81  if (headersString)
82  {
83  var headerLines = headersString.split('\r\n'),
84  count = headerLines.length;
85 
86  while (count--)
87  {
88  var headerLine = headerLines[count],
89  index = headerLine.indexOf(': ');
90  if (index !== CPNotFound)
91  [r setValue:headerLine.substring(index + 2) forKey:headerLine.substring(0, index)];
92  }
93  }
94 
95  return r;
96 }
97 
98 /* @ignore */
99 - (void)_setStatusCode:(int)aStatusCode
100 {
101  _statusCode = aStatusCode;
102 }
103 
107 - (int)statusCode
108 {
109  return _statusCode;
110 }
111 
112 - (void)_setAllResponseHeaders:(CPString)responseHeadersString
113 {
114  _allResponseHeaders = responseHeadersString;
115 }
116 
120 - (CPDictionary)allHeaderFields
121 {
122  // Lazily parse the headers.
123  if (!_responseHeaders)
124  _responseHeaders = [[self class] parseHTTPHeaders:_allResponseHeaders];
125 
126  return _responseHeaders;
127 }
128 
129 @end
A mutable key-value pair collection.
Definition: CPDictionary.h:2
An immutable string (collection of characters).
Definition: CPString.h:2
Protocol agnostic information about a request to a specific URL.
Definition: CPURLResponse.h:2
int length()
Definition: CPString.j:186
CPNotFound
Definition: CPObjJRuntime.j:62
id init()
Definition: CPObject.j:145
Class class()
Definition: CPObject.j:179
Definition: CPURL.h:2