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-08-18 10:57:38 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8b84e97ae68c51f74027c5fd20d8f398ead9b56f
8b84e97a
1 parent
193ea577
Fix casting warnings
Add new test for delegate data handling
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
74 additions
and
9 deletions
Classes/ASIDataCompressor.h
Classes/ASIDataCompressor.m
Classes/ASIDataDecompressor.h
Classes/ASIDataDecompressor.m
Classes/ASIHTTPRequest.m
Classes/Tests/ASIHTTPRequestTests.m
Classes/ASIDataCompressor.h
View file @
8b84e97
...
...
@@ -22,7 +22,7 @@
+
(
id
)
compressor
;
// Compress the passed chunk of data
-
(
NSData
*
)
compressBytes
:(
Bytef
*
)
bytes
length
:(
NSInteger
)
length
error
:(
NSError
**
)
err
;
-
(
NSData
*
)
compressBytes
:(
Bytef
*
)
bytes
length
:(
NS
U
Integer
)
length
error
:(
NSError
**
)
err
;
// Convenience method - pass it some data, and you'll get deflated data back
+
(
NSData
*
)
compressData
:(
NSData
*
)
uncompressedData
error
:(
NSError
**
)
err
;
...
...
Classes/ASIDataCompressor.m
View file @
8b84e97
...
...
@@ -66,7 +66,7 @@
return
nil
;
}
-
(
NSData
*
)
compressBytes
:
(
Bytef
*
)
bytes
length
:
(
NSInteger
)
length
error
:
(
NSError
**
)
err
-
(
NSData
*
)
compressBytes
:
(
Bytef
*
)
bytes
length
:
(
NS
U
Integer
)
length
error
:
(
NSError
**
)
err
{
if
(
length
==
0
)
return
nil
;
...
...
@@ -78,7 +78,7 @@
int
status
;
zStream
.
next_in
=
bytes
;
zStream
.
avail_in
=
length
;
zStream
.
avail_in
=
(
unsigned
int
)
length
;
zStream
.
avail_out
=
0
;
NSError
*
theError
=
nil
;
...
...
@@ -151,7 +151,7 @@
UInt8
inputData
[
DATA_CHUNK_SIZE
];
NSData
*
outputData
;
int
readLength
;
NSInteger
readLength
;
NSError
*
theError
=
nil
;
ASIDataCompressor
*
compressor
=
[
ASIDataCompressor
compressor
];
...
...
Classes/ASIDataDecompressor.h
View file @
8b84e97
...
...
@@ -22,7 +22,7 @@
+
(
id
)
decompressor
;
// Uncompress the passed chunk of data
-
(
NSData
*
)
uncompressBytes
:(
Bytef
*
)
bytes
length
:(
NSInteger
)
length
error
:(
NSError
**
)
err
;
-
(
NSData
*
)
uncompressBytes
:(
Bytef
*
)
bytes
length
:(
NS
U
Integer
)
length
error
:(
NSError
**
)
err
;
// Convenience method - pass it some deflated data, and you'll get inflated data back
+
(
NSData
*
)
uncompressData
:(
NSData
*
)
compressedData
error
:(
NSError
**
)
err
;
...
...
Classes/ASIDataDecompressor.m
View file @
8b84e97
...
...
@@ -65,7 +65,7 @@
return
nil
;
}
-
(
NSData
*
)
uncompressBytes
:
(
Bytef
*
)
bytes
length
:
(
NSInteger
)
length
error
:
(
NSError
**
)
err
-
(
NSData
*
)
uncompressBytes
:
(
Bytef
*
)
bytes
length
:
(
NS
U
Integer
)
length
error
:
(
NSError
**
)
err
{
if
(
length
==
0
)
return
nil
;
...
...
@@ -75,7 +75,7 @@
int
status
;
zStream
.
next_in
=
bytes
;
zStream
.
avail_in
=
length
;
zStream
.
avail_in
=
(
unsigned
int
)
length
;
zStream
.
avail_out
=
0
;
NSError
*
theError
=
nil
;
...
...
@@ -149,7 +149,7 @@
UInt8
inputData
[
DATA_CHUNK_SIZE
];
NSData
*
outputData
;
int
readLength
;
NSInteger
readLength
;
NSError
*
theError
=
nil
;
ASIDataDecompressor
*
decompressor
=
[
ASIDataDecompressor
decompressor
];
...
...
Classes/ASIHTTPRequest.m
View file @
8b84e97
...
...
@@ -24,7 +24,7 @@
#import "ASIDataCompressor.h"
// Automatically set on build
NSString
*
ASIHTTPRequestVersion
=
@"v1.7-4
3 2010-08-17
"
;
NSString
*
ASIHTTPRequestVersion
=
@"v1.7-4
4 2010-08-18
"
;
NSString
*
const
NetworkRequestErrorDomain
=
@"ASIHTTPRequestErrorDomain"
;
...
...
Classes/Tests/ASIHTTPRequestTests.m
View file @
8b84e97
...
...
@@ -667,6 +667,71 @@
GHAssertTrue
(
success
,
@"Failed to download data to a file"
);
}
-
(
void
)
request
:
(
ASIHTTPRequest
*
)
request
didGetMoreData
:
(
NSData
*
)
data
{
[[
self
responseData
]
appendData
:
data
];
}
-
(
void
)
downloadFinished
:
(
ASIHTTPRequest
*
)
request
{
finished
=
YES
;
}
-
(
void
)
testCompressedResponseDelegateDataHandling
{
finished
=
NO
;
[
self
setResponseData
:[
NSMutableData
data
]];
NSURL
*
url
=
[[[
NSURL
alloc
]
initWithString
:
@"http://asi/ASIHTTPRequest/tests/the_hound_of_the_baskervilles.text"
]
autorelease
];
ASIHTTPRequest
*
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
startSynchronous
];
NSString
*
response
=
[
request
responseString
];
// Now download again, using the delegate to handle the data
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setDelegate
:
self
];
[
request
setDidReceiveDataSelector
:
@selector
(
request
:
didGetMoreData
:
)];
[
request
setDidFinishSelector
:
@selector
(
downloadFinished
:)];
[
request
setShouldWaitToInflateCompressedResponses
:
NO
];
[
request
startSynchronous
];
while
(
!
finished
)
{
sleep
(
1
);
}
NSString
*
delegateResponse
=
[[[
NSString
alloc
]
initWithBytes
:[
responseData
bytes
]
length
:[
responseData
length
]
encoding
:[
request
responseEncoding
]]
autorelease
];
BOOL
success
=
[
delegateResponse
isEqualToString
:
response
];
GHAssertTrue
(
success
,
@"Failed to correctly download the response using a delegate"
);
// Test again without compression
finished
=
NO
;
[
self
setResponseData
:[
NSMutableData
data
]];
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setAllowCompressedResponse
:
NO
];
[
request
startSynchronous
];
response
=
[
request
responseString
];
// Now download again, using the delegate to handle the data
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:
url
]
autorelease
];
[
request
setDelegate
:
self
];
[
request
setDidReceiveDataSelector
:
@selector
(
request
:
didGetMoreData
:
)];
[
request
setDidFinishSelector
:
@selector
(
downloadFinished
:)];
[
request
setAllowCompressedResponse
:
NO
];
[
request
startSynchronous
];
while
(
!
finished
)
{
sleep
(
1
);
}
delegateResponse
=
[[[
NSString
alloc
]
initWithBytes
:[
responseData
bytes
]
length
:[
responseData
length
]
encoding
:[
request
responseEncoding
]]
autorelease
];
success
=
[
delegateResponse
isEqualToString
:
response
];
GHAssertTrue
(
success
,
@"Failed to correctly download the response using a delegate"
);
}
-
(
void
)
testDownloadProgress
{
...
...
Please
register
or
login
to post a comment