GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: a tiny graphical app kit for ruby
Homepage: http://code.whytheluckystiff.net/shoes
Clone URL: git://github.com/why/shoes.git
 * shoes/http/nsurl.m: status code and header handling on os x.
why (author)
Tue Jul 22 14:01:03 -0700 2008
commit  943e2380cb0d0953f44f3249abf60cfde07b66e6
tree    8f2638a75f79b3cf6af0dc6954ee2b852f9f612e
parent  8480109d1e4fa9fc7ac3ff17d2cf37c2f4c63f6c
...
68
69
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
72
 
73
74
75
...
101
102
103
 
104
105
106
...
137
138
139
 
 
140
...
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
134
135
136
137
138
139
140
...
171
172
173
174
175
176
0
@@ -68,8 +68,41 @@
0
     down = [[NSURLDownload alloc] initWithRequest: nsreq delegate: self];
0
   }
0
 }
0
+- (void)readHeaders: (NSURLResponse *)response
0
+{
0
+ if ([response respondsToSelector:@selector(allHeaderFields)])
0
+ {
0
+ NSHTTPURLResponse* httpresp = (NSHTTPURLResponse *)response;
0
+ if ([httpresp statusCode])
0
+ {
0
+ shoes_download_event event;
0
+ event.stage = SHOES_HTTP_STATUS;
0
+ event.status = [httpresp statusCode];
0
+ if (handler != NULL) handler(&event, data);
0
+ }
0
+
0
+ NSDictionary *hdrs = [httpresp allHeaderFields];
0
+ if (hdrs)
0
+ {
0
+ NSString *key;
0
+ NSEnumerator *keys = [hdrs keyEnumerator];
0
+ while (key = [keys nextObject])
0
+ {
0
+ NSString *val = [hdrs objectForKey: key];
0
+ shoes_download_event event;
0
+ event.stage = SHOES_HTTP_HEADER;
0
+ event.hkey = [key UTF8String];
0
+ event.hkeylen = strlen(event.hkey);
0
+ event.hval = [val UTF8String];
0
+ event.hvallen = strlen(event.hval);
0
+ if (handler != NULL) handler(&event, data);
0
+ }
0
+ }
0
+ }
0
+}
0
 - (void)connection: (NSURLConnection *)c didReceiveResponse: (NSURLResponse *)response
0
 {
0
+ [self readHeaders: response];
0
   size = total = 0;
0
   if ([response expectedContentLength] != NSURLResponseUnknownLength)
0
     total = [response expectedContentLength];
0
@@ -101,6 +134,7 @@
0
 }
0
 - (void)download: (NSURLDownload *)download didReceiveResponse: (NSURLResponse *)response
0
 {
0
+ [self readHeaders: response];
0
   size = total = 0;
0
   if ([response expectedContentLength] != NSURLResponseUnknownLength)
0
     total = [response expectedContentLength];
0
@@ -137,4 +171,6 @@ shoes_queue_download(shoes_download_request *req)
0
 VALUE
0
 shoes_http_error(SHOES_DOWNLOAD_ERROR code)
0
 {
0
+ char *errorString = [[code localizedDescription] UTF8String];
0
+ return rb_str_new2(errorString);
0
 }

Comments

    No one has commented yet.