2
<!DOCTYPE gsdoc PUBLIC "-//GNUstep//DTD gsdoc 0.6.6//EN" "http://www.gnustep.org/gsdoc-0_6_6.xml">
3
<gsdoc base="NSURLHandle" prev="NSURL" next="NSUnarchiver" up="Base">
5
<title>NSURLHandle</title>
6
<author name="Richard Frith-Macdonald">
7
<email address="rfm@gnu.org"/>
8
<url url="http://www.gnustep.org/developers/whoiswho.html"/>
10
<author name="Mark Allison">
11
<email address="mark@brainstorm.co.uk"/>
12
<url url="http://www.brainstorm.co.uk"/>
14
<version>$Revision: 1.13 $</version>
15
<date>$Date: 2001/12/12 14:10:13 $</date>
19
<heading>NSURLHandle</heading>
20
<class name="NSURLHandle" super="NSObject">
21
<declared>Foundation/NSURLHandle.h</declared>
24
An NSURLHandle instance is used to manage the resource data
25
corresponding to an NSURL object. A single NSURLHandle can
26
be used to manage multiple NSURL objects as long as those
27
objects all refer to the same resource.
30
Different NSURLHandle subclasses are used to manage different
31
types of URL (usually based on the scheme of the URL), and you
32
can register new subclasses to extend (or replace) the
36
GNUstep comes with private subclasses to handle the common
41
<ref id="GSFileURLHandle">GSFileURLHandle</ref> for
42
<code>file:</code> (local file I/O)
45
<ref id="GSHTTPURLHandle">GSHTTPURLHandle</ref> for
46
<code>http</code> and <code>shttp</code> (webserver) access.
51
<method type="Class" factory="yes">
52
<sel>URLHandleClassForURL:</sel>
53
<arg type="NSURL*">anURL</arg>
55
Returns the most recently registered NSURLHandle subclass that
56
responds to <ref id="canInitWithURL:">canInitWithURL:</ref>
57
with <code>YES</code>. If there is no such subclass, returns nil.
61
<method type="NSURLHandle*" factory="yes">
62
<sel>cachedHandleForURL:</sel>
63
<arg type="NSURL*">anURL</arg>
65
Returns a previously created object that handles the specified
66
URL (if any exists), otherwise returns nil.
70
<method type="BOOL" factory="yes" id="canInitWithURL:"
72
<sel>canInitWithURL:</sel>
73
<arg type="NSURL*">anURL</arg>
75
Implemented by subclasses to say which URLs they can handle.
76
This method is used to determine which subclasses can be used
77
to handle a particular URL.
81
<method type="void" factory="yes">
82
<sel>registerURLHandleClass:</sel>
83
<arg type="Class">anURLHandleSubclass</arg>
85
Used to register a subclass as being available to handle URLs.
91
<arg type="id<NSURLHandleClient>">client</arg>
93
Adds an object conforming to the
94
<ref id="NSURLHandleClient">NSURLHandleClient protocol</ref>
95
as a client of the URL handle.
99
<method type="NSData*">
100
<sel>availableResourceData</sel>
102
Returns the resource data that is currently available for the
103
handle. This may be a partially loaded resource or may be
104
empty of no data has been loaded yet.
109
<sel>backgroundLoadDidFailWithReason:</sel>
110
<arg type="NSString*">reason</arg>
112
This method should be called when a background load fails.
113
The method passes the failure notification to the clients of
114
the handle - so subclasses should call super's implementation
115
at the end of their implementation of this method.
120
<sel>beginLoadInBackground</sel>
122
This method is called by when a background load begins.
123
Subclasses should call super's implementation at
124
the end of their implementation of this method.
128
<method type="void" id="cancelLoadInBackground">
129
<sel>cancelLoadInBackground</sel>
131
This method should be called to cancel a load currently in
132
progress. The method calls
133
<ref id="endLoadInBackground">endLoadInBackground</ref>
134
Subclasses should call super's implementation at
135
the end of their implementation of this method.
140
<sel>didLoadBytes:</sel>
141
<arg type="NSData*">newBytes</arg>
142
<sel>loadComplete:</sel>
143
<arg type="BOOL">yorn</arg>
145
This method must be called by subclasses whenever data is
150
<method type="void" id="endLoadInBackground">
151
<sel>endLoadInBackground</sel>
153
This method is called to stop any background loading process.
154
<ref id="cancelLoadInBackground">cancelLoadInBackground</ref>
155
uses this method to cancel loading.
156
Subclasses should call super's implementation at
157
the end of their implementation of this method.
161
<method type="NSString*">
162
<sel>failureReason</sel>
164
Returns the failure reason for the last failure to load
170
<sel>flushCachedData</sel>
172
Flushes any cached resource data.
176
<method type="init" init="yes" override="subclass">
177
<sel>initWithURL:</sel>
178
<arg type="NSURL*">url</arg>
180
<arg type="BOOL">yesno</arg>
182
Initialises a handle with the specified URL.
183
The flag determines whether the handle will cache resource data
184
and respond to requests from equivalent URLs for the cached data.
188
<method type="void" override="subclass">
189
<sel>loadInBackground</sel>
191
Starts (or queues) loading of the handle's resource data
192
in the background (asynchronously).
196
<method type="NSData*" id ="loadInForeground">
197
<sel>loadInForeground</sel>
199
Loads the handle's resource data in the foreground (synchronously).
200
This may be implemented by starting a background load and
201
waiting for it to complete.
205
<method type="id" override="subclass">
206
<sel>propertyForKey:</sel>
207
<arg type="NSString*">propertyKey</arg>
209
Returns the property for the specified key, or nil if the
214
<method type="id" override="subclass">
215
<sel>propertyForKeyIfAvailable:</sel>
216
<arg type="NSString*">propertyKey</arg>
218
Returns the property for the specified key, but only if the
219
handle does not need to do any work to retrieve it.
224
<sel>removeClient:</sel>
225
<arg type="id<NSURLHandleClient>">client</arg>
227
Removes an object from them list of clients notified of
228
resource loading events by the URL handle.
232
<method type="NSData*">
233
<sel>resourceData</sel>
235
Returns the resource data belonging to the handler.
236
Calls <ref id="loadInForeground">loadInForeground</ref> if
241
<method type="NSURLHandleStatus">
244
Returns the current status of the handle.
248
<method type="BOOL" override="subclass">
249
<sel>writeData:</sel>
250
<arg type="NSData*">data</arg>
253
Writes resource data to the handle. Returns YES on success,
257
The GNUstep implementation sets the specified data as
258
information to be POSTed to the URL next time it is loaded.
263
<method type="BOOL" override="subclass">
264
<sel>writeProperty:</sel>
265
<arg type="id">propertyValue</arg>
267
<arg type="NSString*">key</arg>
270
Sets a property for handle.
271
Returns YES on success, NO on failure.
274
The GNUstep implementation sets the property as a header
275
to be sent the next time the URL is loaded, and recognizes
276
some special property keys which control the behavior of
282
<standards><MacOS-X/><NotOpenStep/></standards>
285
<protocol name="NSURLHandleClient">
286
<declared>Foundation/NSURLHandle.h</declared>
291
<sel>URLHandleResourceDidBeginLoading:</sel>
292
<arg type="NSURLHandle*">sender</arg>
294
Sent by the NSURLHandle object when it begins loading
300
<sel>URLHandleResourceDidCancelLoading:</sel>
301
<arg type="NSURLHandle*">sender</arg>
303
Sent by the NSURLHandle object when resource loading is canceled
304
by programmatic request (rather than by failure).
309
<sel>URLHandleResourceDidFinishLoading:</sel>
310
<arg type="NSURLHandle*">sender</arg>
312
Sent by the NSURLHandle object when it completes loading
318
<sel>URLHandle:</sel>
319
<arg type="NSURLHandle*">sender</arg>
320
<sel>resourceDidBecomeAvailable:</sel>
321
<arg type="NSData*">data</arg>
323
Sent by the NSURLHandle object when some data becomes available
329
<sel>URLHandle:</sel>
330
<arg type="NSURLHandle*">sender</arg>
331
<sel>resourceDidFailLoadingWithReason:</sel>
332
<arg type="NSString*">reason</arg>
334
Sent by the NSURLHandle object on resource load failure.
335
Supplies a human readable failure reason.
339
<standards><MacOS-X/><NotOpenStep/></standards>
342
<type name="NSURLHandleStatus">
343
<typespec>int</typespec>
344
<declared>Foundation/NSURLHandle.h</declared>
346
An NSURLHandleStatus is used to report the current state of an
347
NSURLHandle object, it can take the following values -
349
<item>NSURLHandleNotLoaded</item>
350
<item>NSURLHandleLoadSucceeded</item>
351
<item>NSURLHandleLoadInProgress</item>
352
<item>NSURLHandleLoadFailed</item>
355
<standards><MacOS-X/><NotOpenStep/></standards>
360
<heading>GSFileURLHandle</heading>
361
<class name="GSFileURLHandle" super="NSURLHandle" id = "GSFileURLHandle">
364
This is a <em>PRIVATE</em> subclass of NSURLHandle.
365
It is documented here in order to give you information about the
366
default behavior of an NSURLHandle created to deal with a URL
367
that has the FILE scheme. The name and/or other
368
implementation details of this class may be changed at any time.
371
A GSFileURLHandle instance is used to manage files on the local
372
file-system of your machine.
377
<sel>propertyForKey:</sel>
378
<arg type="NSString*">propertyKey</arg>
380
Gets file attribute information for the file represented by
381
the handle, using the same dictionary keys as the
387
<sel>writeData:</sel>
388
<arg type="NSData*">data</arg>
390
Writes the specified data as the contents of the file
391
represented by the handle.
396
<sel>writeProperty:</sel>
397
<arg type="id">propertyValue</arg>
399
<arg type="NSString*">key</arg>
401
Changes the attributes of the file represented by this handle.
402
This method uses the same dictionary keys as the NSFileManger
407
<standards><NotMacOS-X/><NotOpenStep/></standards>
412
<heading>GSHTTPURLHandle</heading>
413
<class name="GSHTTPURLHandle" super="NSURLHandle" id = "GSHTTPURLHandle">
416
This is a <em>PRIVATE</em> subclass of NSURLHandle.
417
It is documented here in order to give you information about the
418
default behavior of an NSURLHandle created to deal with a URL
419
that has either the <code>http</code> or <code>https</code> scheme.
420
The name and/or other implementation details of this class
421
may be changed at any time.
424
A GSHTTPURLHandle instance is used to manage connections to
425
<code>http</code> and <code>https</code> URLs.
426
Secure connections are handled automatically
427
(using openSSL) for URLs with the scheme <code>https</code>.
428
Connection via proxy server is supported, as is proxy tunneling
429
for secure connections. Basic parsing of <code>http</code>
430
headers is performed to extract <code>http</code> status
431
information, cookies etc. Cookies are
432
retained and automatically sent during subsequent requests where
436
Header information from the current page may be obtained using
437
-propertyForKey and -propertyForKeyIfAvailable. <code>HTTP</code>
438
status information can be retrieved as by calling either of these
439
methods specifying one of the following keys:
443
NSHTTPPropertyStatusCodeKey - numeric status code
446
NSHTTPPropertyStatusReasonKey - text describing status
449
NSHTTPPropertyServerHTTPVersionKey - <code>http</code>
450
version supported by remote server
454
According to MacOS-X headers, the following should also
455
be supported, but currently are not:
458
<item>NSHTTPPropertyRedirectionHeadersKey</item>
459
<item>NSHTTPPropertyErrorPageDataKey</item>
462
The omission of these headers is not viewed as important at
463
present, since the MacOS-X public beta implementation doesn't
467
Other calls to -propertyForKey and -propertyForKeyIfAvailable may
468
be made specifying a <code>http</code> header field name.
469
For example specifying a key name of "Content-Length"
470
would return the value of the "Content-Length" header
474
<ref id="GSHTTPURLHandle-writeProperty:forKey:">
475
-writeProperty:forKey:</ref> can be used to specify the parameters
476
for the <code>http</code> request. The default request uses the
477
"GET" method when fetching a page, and the
478
"POST" method when using -writeData:.
479
This can be over-ridden by calling -writeProperty:forKey: with
480
the key name "GSHTTPPropertyMethodKey" and specifying an
481
alternative method (i.e "PUT").
484
A Proxy may be specified by calling -writeProperty:forKey:
485
with the keys "GSHTTPPropertyProxyHostKey" and
486
"GSHTTPPropertyProxyPortKey" to set the host and port
487
of the proxy server respectively. The GSHTTPPropertyProxyHostKey
488
property can be set to either the IP address or the hostname of
489
the proxy server. If an attempt is made to load a page via a
490
secure connection when a proxy is specified, GSHTTPURLHandle will
491
attempt to open an SSL Tunnel through the proxy.
496
<sel>propertyForKey:</sel>
497
<arg type="NSString*">propertyKey</arg>
499
If necessary, this method calls -loadInForeground to send a
500
request to the webserver, and get a page back. It then returns
501
the property for the specified key -
504
NSHTTPPropertyStatusCodeKey - numeric status code returned
508
NSHTTPPropertyStatusReasonKey - text describing status of
512
NSHTTPPropertyServerHTTPVersionKey - <code>http</code>
513
version supported by remote server
516
Other keys are taken to be the names of <code>http</code>
517
headers and the corresponding header value (or nil if there
518
is none) is returned.
525
<sel>writeData:</sel>
526
<arg type="NSData*">data</arg>
528
Writes the specified data as the body of an <code>http</code>
529
or <code>https</code> request to the web server.
530
Returns YES on success,
531
NO on failure. By default, this method performs a POST operation.
532
On completion, the resource data for this handle is set to the
533
page returned by the request.
537
<method type="BOOL" id="GSHTTPURLHandle-writeProperty:forKey:">
538
<sel>writeProperty:</sel>
539
<arg type="id">propertyValue</arg>
541
<arg type="NSString*">key</arg>
543
Sets a property to be used in the next request made by this handle.
544
The property is set as a header in the next request, unless it is
545
one of the following -
548
GSHTTPPropertyBodyKey - set an NSData item to be sent to
549
the server as the body of the request.
552
GSHTTPPropertyMethodKey - override the default method of
553
the request (eg. "PUT").
556
GSHTTPPropertyProxyHostKey - specify the name or IP address
557
of a host to proxy through.
560
GSHTTPPropertyProxyPortKey - specify the port number to
561
connect to on the proxy host. If not give, this defaults
562
to 8080 for <code>http</code> and 4430 for <code>https</code>.
568
<standards><NotMacOS-X/><NotOpenStep/></standards>