Toggle navigation
Toggle navigation
This project
Loading...
Sign in
iOS
/
asi-http-request
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Ben Copsey
2010-05-26 14:40:37 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
75bf276c46c529feb77ba2d92bd1b41cd5728b94
75bf276c
1 parent
65c5684d
S3 - use per-thread NSDateFormatter. Many thanks once again to Tom Andersen!
Add same to Cloud Files
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
23 deletions
Classes/ASIHTTPRequest.m
Classes/CloudFiles/ASICloudFilesRequest.m
Classes/S3/ASIS3BucketRequest.m
Classes/S3/ASIS3Request.h
Classes/S3/ASIS3Request.m
Classes/S3/ASIS3ServiceRequest.m
Classes/ASIHTTPRequest.m
View file @
75bf276
...
...
@@ -23,7 +23,7 @@
// Automatically set on build
NSString
*
ASIHTTPRequestVersion
=
@"v1.6.2-1
0 2010-05-14
"
;
NSString
*
ASIHTTPRequestVersion
=
@"v1.6.2-1
1 2010-05-26
"
;
NSString
*
const
NetworkRequestErrorDomain
=
@"ASIHTTPRequestErrorDomain"
;
...
...
Classes/CloudFiles/ASICloudFilesRequest.m
View file @
75bf276
...
...
@@ -103,15 +103,21 @@ static NSRecursiveLock *accessDetailsLock = nil;
#pragma mark -
#pragma mark Date Parser
-
(
NSDate
*
)
dateFromString
:
(
NSString
*
)
dateString
{
NSDateFormatter
*
dateFormatter
=
[[
NSDateFormatter
alloc
]
init
];
[
dateFormatter
setLocale
:[[[
NSLocale
alloc
]
initWithLocaleIdentifier
:
@"en_US_POSIX"
]
autorelease
]];
// example: 2009-11-04T19:46:20.192723
[
dateFormatter
setDateFormat
:
@"yyyy-MM-dd'T'H:mm:ss.SSSSSS"
];
NSDate
*
date
=
[
dateFormatter
dateFromString
:
dateString
];
[
dateFormatter
release
];
return
date
;
-
(
NSDate
*
)
dateFromString
:
(
NSString
*
)
dateString
{
// We store our date formatter in the calling thread's dictionary
// NSDateFormatter is not thread-safe, this approach ensures each formatter is only used on a single thread
// This formatter can be reused many times in parsing a single response, so it would be expensive to keep creating new date formatters
NSMutableDictionary
*
threadDict
=
[[
NSThread
currentThread
]
threadDictionary
];
NSDateFormatter
*
dateFormatter
=
[
threadDict
objectForKey
:
@"ASICloudFilesResponseDateFormatter"
];
if
(
dateFormatter
==
nil
)
{
dateFormatter
=
[[[
NSDateFormatter
alloc
]
init
]
autorelease
];
[
dateFormatter
setLocale
:[[[
NSLocale
alloc
]
initWithLocaleIdentifier
:
@"en_US_POSIX"
]
autorelease
]];
// example: 2009-11-04T19:46:20.192723
[
dateFormatter
setDateFormat
:
@"yyyy-MM-dd'T'H:mm:ss.SSSSSS"
];
[
threadDict
setObject
:
dateFormatter
forKey
:
@"ASICloudFilesResponseDateFormatter"
];
}
return
[
dateFormatter
dateFromString
:
dateString
];
}
@end
...
...
Classes/S3/ASIS3BucketRequest.m
View file @
75bf276
...
...
@@ -127,7 +127,7 @@
}
else
if
([
elementName
isEqualToString
:
@"Key"
])
{
[[
self
currentObject
]
setKey
:[
self
currentXMLElementContent
]];
}
else
if
([
elementName
isEqualToString
:
@"LastModified"
])
{
[[
self
currentObject
]
setLastModified
:[[
ASIS3Request
d
ateFormatter
]
dateFromString
:[
self
currentXMLElementContent
]]];
[[
self
currentObject
]
setLastModified
:[[
ASIS3Request
S3ResponseD
ateFormatter
]
dateFromString
:[
self
currentXMLElementContent
]]];
}
else
if
([
elementName
isEqualToString
:
@"ETag"
])
{
[[
self
currentObject
]
setETag
:[
self
currentXMLElementContent
]];
}
else
if
([
elementName
isEqualToString
:
@"Size"
])
{
...
...
Classes/S3/ASIS3Request.h
View file @
75bf276
...
...
@@ -71,7 +71,11 @@ typedef enum _ASIS3ErrorType {
# pragma mark helpers
// Returns a date formatter than can be used to parse a date from S3
+
(
NSDateFormatter
*
)
dateFormatter
;
+
(
NSDateFormatter
*
)
S3ResponseDateFormatter
;
// Returns a date formatter than can be used to send a date header to S3
+
(
NSDateFormatter
*
)
S3RequestDateFormatter
;
// URL-encodes an S3 key so it can be used in a url
// You shouldn't normally need to use this yourself
...
...
Classes/S3/ASIS3Request.m
View file @
75bf276
...
...
@@ -17,8 +17,6 @@ NSString* const ASIS3AccessPolicyAuthenticatedRead = @"authenticated-read";
static
NSString
*
sharedAccessKey
=
nil
;
static
NSString
*
sharedSecretAccessKey
=
nil
;
static
NSDateFormatter
*
dateFormatter
=
nil
;
// Private stuff
@interface
ASIS3Request
()
+
(
NSData
*
)
HMACSHA1withKey
:
(
NSString
*
)
key
forString
:
(
NSString
*
)
string
;
...
...
@@ -49,11 +47,7 @@ static NSDateFormatter *dateFormatter = nil;
-
(
void
)
setDate
:
(
NSDate
*
)
date
{
NSDateFormatter
*
headerDateFormatter
=
[[[
NSDateFormatter
alloc
]
init
]
autorelease
];
// Prevent problems with dates generated by other locales (tip from: http://rel.me/t/date/)
[
headerDateFormatter
setLocale
:[[[
NSLocale
alloc
]
initWithLocaleIdentifier
:
@"en_US_POSIX"
]
autorelease
]];
[
headerDateFormatter
setDateFormat
:
@"EEE, d MMM yyyy HH:mm:ss Z"
];
[
self
setDateString
:[
headerDateFormatter
stringFromDate
:
date
]];
[
self
setDateString
:[[
ASIS3Request
S3RequestDateFormatter
]
stringFromDate
:
date
]];
}
-
(
ASIHTTPRequest
*
)
HEADRequest
...
...
@@ -229,17 +223,39 @@ static NSDateFormatter *dateFormatter = nil;
return
path
;
}
+
(
NSDateFormatter
*
)
dateFormatter
// Thanks to Tom Andersen for pointing out the threading issues and providing this code!
+
(
NSDateFormatter
*
)
S3ResponseDateFormatter
{
if
(
!
dateFormatter
)
{
dateFormatter
=
[[
NSDateFormatter
alloc
]
init
];
// We store our date formatter in the calling thread's dictionary
// NSDateFormatter is not thread-safe, this approach ensures each formatter is only used on a single thread
// This formatter can be reused 1000 times in parsing a single response, so it would be expensive to keep creating new date formatters
NSMutableDictionary
*
threadDict
=
[[
NSThread
currentThread
]
threadDictionary
];
NSDateFormatter
*
dateFormatter
=
[
threadDict
objectForKey
:
@"ASIS3ResponseDateFormatter"
];
if
(
dateFormatter
==
nil
)
{
dateFormatter
=
[[[
NSDateFormatter
alloc
]
init
]
autorelease
];
[
dateFormatter
setLocale
:[[[
NSLocale
alloc
]
initWithLocaleIdentifier
:
@"en_US_POSIX"
]
autorelease
]];
[
dateFormatter
setTimeZone
:[
NSTimeZone
timeZoneWithAbbreviation
:
@"UTC"
]];
[
dateFormatter
setDateFormat
:
@"yyyy-MM-dd'T'HH:mm:ss'.000Z'"
];
[
threadDict
setObject
:
dateFormatter
forKey
:
@"ASIS3ResponseDateFormatter"
];
}
return
dateFormatter
;
}
+
(
NSDateFormatter
*
)
S3RequestDateFormatter
{
NSMutableDictionary
*
threadDict
=
[[
NSThread
currentThread
]
threadDictionary
];
NSDateFormatter
*
dateFormatter
=
[
threadDict
objectForKey
:
@"ASIS3RequestHeaderDateFormatter"
];
if
(
dateFormatter
==
nil
)
{
dateFormatter
=
[[[
NSDateFormatter
alloc
]
init
]
autorelease
];
// Prevent problems with dates generated by other locales (tip from: http://rel.me/t/date/)
[
dateFormatter
setLocale
:[[[
NSLocale
alloc
]
initWithLocaleIdentifier
:
@"en_US_POSIX"
]
autorelease
]];
[
dateFormatter
setTimeZone
:[
NSTimeZone
timeZoneWithAbbreviation
:
@"UTC"
]];
[
dateFormatter
setDateFormat
:
@"EEE, d MMM yyyy HH:mm:ss Z"
];
[
threadDict
setObject
:
dateFormatter
forKey
:
@"ASIS3RequestHeaderDateFormatter"
];
}
return
dateFormatter
;
}
// From: http://stackoverflow.com/questions/476455/is-there-a-library-for-iphone-to-work-with-hmac-sha-1-encoding
...
...
Classes/S3/ASIS3ServiceRequest.m
View file @
75bf276
...
...
@@ -58,7 +58,7 @@
}
else
if
([
elementName
isEqualToString
:
@"Name"
])
{
[[
self
currentBucket
]
setName
:[
self
currentXMLElementContent
]];
}
else
if
([
elementName
isEqualToString
:
@"CreationDate"
])
{
[[
self
currentBucket
]
setCreationDate
:[[
ASIS3Request
d
ateFormatter
]
dateFromString
:[
self
currentXMLElementContent
]]];
[[
self
currentBucket
]
setCreationDate
:[[
ASIS3Request
S3ResponseD
ateFormatter
]
dateFromString
:[
self
currentXMLElementContent
]]];
}
else
if
([
elementName
isEqualToString
:
@"ID"
])
{
[
self
setOwnerID
:[
self
currentXMLElementContent
]];
}
else
if
([
elementName
isEqualToString
:
@"DisplayName"
])
{
...
...
Please
register
or
login
to post a comment