mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-28 20:55:32 +08:00
Added specs for zero-length Content-Length header when params is nil or empty
This commit is contained in:
@@ -178,7 +178,9 @@
|
|||||||
if ([_params respondsToSelector:@selector(HTTPHeaderValueForContentLength)]) {
|
if ([_params respondsToSelector:@selector(HTTPHeaderValueForContentLength)]) {
|
||||||
[_URLRequest setValue:[NSString stringWithFormat:@"%d", [_params HTTPHeaderValueForContentLength]] forHTTPHeaderField:@"Content-Length"];
|
[_URLRequest setValue:[NSString stringWithFormat:@"%d", [_params HTTPHeaderValueForContentLength]] forHTTPHeaderField:@"Content-Length"];
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
[_URLRequest setValue:@"0" forHTTPHeaderField:@"Content-Length"];
|
||||||
|
}
|
||||||
|
|
||||||
// Add authentication headers so we don't have to deal with an extra cycle for each message requiring basic auth.
|
// Add authentication headers so we don't have to deal with an extra cycle for each message requiring basic auth.
|
||||||
if (self.forceBasicAuthentication) {
|
if (self.forceBasicAuthentication) {
|
||||||
|
|||||||
@@ -31,7 +31,6 @@
|
|||||||
/* End PBXAggregateTarget section */
|
/* End PBXAggregateTarget section */
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
13924B7913AAB91700DD5078 /* libUISpec.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13924B7813AAB91700DD5078 /* libUISpec.a */; };
|
|
||||||
25064735138DF17C0002F2FE /* RKManagedObjectSeeder.m in Sources */ = {isa = PBXBuildFile; fileRef = 253A088912551D8D00976E89 /* RKManagedObjectSeeder.m */; };
|
25064735138DF17C0002F2FE /* RKManagedObjectSeeder.m in Sources */ = {isa = PBXBuildFile; fileRef = 253A088912551D8D00976E89 /* RKManagedObjectSeeder.m */; };
|
||||||
250C296C13411E60000A3551 /* RKRequestQueueSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 250C296B13411E60000A3551 /* RKRequestQueueSpec.m */; };
|
250C296C13411E60000A3551 /* RKRequestQueueSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 250C296B13411E60000A3551 /* RKRequestQueueSpec.m */; };
|
||||||
250C29FD134185D2000A3551 /* RKNetwork.h in Headers */ = {isa = PBXBuildFile; fileRef = 250C29FB134185CE000A3551 /* RKNetwork.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
250C29FD134185D2000A3551 /* RKNetwork.h in Headers */ = {isa = PBXBuildFile; fileRef = 250C29FB134185CE000A3551 /* RKNetwork.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
@@ -110,6 +109,7 @@
|
|||||||
256FD651112C7B780077F340 /* RKMappableObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 256FD64F112C7B780077F340 /* RKMappableObject.m */; };
|
256FD651112C7B780077F340 /* RKMappableObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 256FD64F112C7B780077F340 /* RKMappableObject.m */; };
|
||||||
256FD652112C7B780077F340 /* RKMappableAssociation.m in Sources */ = {isa = PBXBuildFile; fileRef = 256FD650112C7B780077F340 /* RKMappableAssociation.m */; };
|
256FD652112C7B780077F340 /* RKMappableAssociation.m in Sources */ = {isa = PBXBuildFile; fileRef = 256FD650112C7B780077F340 /* RKMappableAssociation.m */; };
|
||||||
256FDE55112DB0B90077F340 /* RKObjectMapperSpecModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 256FDE54112DB0B90077F340 /* RKObjectMapperSpecModel.m */; };
|
256FDE55112DB0B90077F340 /* RKObjectMapperSpecModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 256FDE54112DB0B90077F340 /* RKObjectMapperSpecModel.m */; };
|
||||||
|
25716F6F13D7979A00572BD9 /* libUISpec.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13924B7513AAB8F500DD5078 /* libUISpec.a */; };
|
||||||
257D2D7013759D70008E9649 /* RKObjectMappingResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 257D2D6E13759D6F008E9649 /* RKObjectMappingResult.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
257D2D7013759D70008E9649 /* RKObjectMappingResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 257D2D6E13759D6F008E9649 /* RKObjectMappingResult.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
257D2D7113759D70008E9649 /* RKObjectMappingResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 257D2D6F13759D6F008E9649 /* RKObjectMappingResult.m */; };
|
257D2D7113759D70008E9649 /* RKObjectMappingResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 257D2D6F13759D6F008E9649 /* RKObjectMappingResult.m */; };
|
||||||
257FB677139559A4003A628E /* RKManagedObjectMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 257FB675139559A4003A628E /* RKManagedObjectMapping.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
257FB677139559A4003A628E /* RKManagedObjectMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 257FB675139559A4003A628E /* RKManagedObjectMapping.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
@@ -755,7 +755,7 @@
|
|||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
13924B7913AAB91700DD5078 /* libUISpec.a in Frameworks */,
|
25716F6F13D7979A00572BD9 /* libUISpec.a in Frameworks */,
|
||||||
25A1CB50138419D900A7D5C9 /* libRestKitJSONParserJSONKit.a in Frameworks */,
|
25A1CB50138419D900A7D5C9 /* libRestKitJSONParserJSONKit.a in Frameworks */,
|
||||||
25A1CB51138419D900A7D5C9 /* libRestKitJSONParserSBJSON.a in Frameworks */,
|
25A1CB51138419D900A7D5C9 /* libRestKitJSONParserSBJSON.a in Frameworks */,
|
||||||
25A1CB52138419D900A7D5C9 /* libRestKitXMLParserLibxml.a in Frameworks */,
|
25A1CB52138419D900A7D5C9 /* libRestKitXMLParserLibxml.a in Frameworks */,
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
launchStyle = "0"
|
launchStyle = "0"
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
enablesOpenGLESFrameCapture = "YES">
|
debugDocumentVersioning = "YES">
|
||||||
<BuildableProductRunnable>
|
<BuildableProductRunnable>
|
||||||
<BuildableReference
|
<BuildableReference
|
||||||
BuildableIdentifier = "primary"
|
BuildableIdentifier = "primary"
|
||||||
@@ -87,13 +87,13 @@
|
|||||||
</EnvironmentVariable>
|
</EnvironmentVariable>
|
||||||
<EnvironmentVariable
|
<EnvironmentVariable
|
||||||
key = "UISPEC_SPEC"
|
key = "UISPEC_SPEC"
|
||||||
value = "RKManagedObjectStoreSpec"
|
value = "RKRequestSpec"
|
||||||
isEnabled = "YES">
|
isEnabled = "YES">
|
||||||
</EnvironmentVariable>
|
</EnvironmentVariable>
|
||||||
<EnvironmentVariable
|
<EnvironmentVariable
|
||||||
key = "UISPEC_EXAMPLE"
|
key = "UISPEC_EXAMPLE"
|
||||||
value = "itShouldAllowYouToPOSTAnObjectAndMapBackNonNestedContent"
|
value = "itShouldPUTWithParams"
|
||||||
isEnabled = "NO">
|
isEnabled = "YES">
|
||||||
</EnvironmentVariable>
|
</EnvironmentVariable>
|
||||||
<EnvironmentVariable
|
<EnvironmentVariable
|
||||||
key = "NSAutoreleaseHaltOnNoPool"
|
key = "NSAutoreleaseHaltOnNoPool"
|
||||||
@@ -110,7 +110,8 @@
|
|||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
savedToolIdentifier = ""
|
savedToolIdentifier = ""
|
||||||
useCustomWorkingDirectory = "NO"
|
useCustomWorkingDirectory = "NO"
|
||||||
buildConfiguration = "Release">
|
buildConfiguration = "Release"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
<BuildableProductRunnable>
|
<BuildableProductRunnable>
|
||||||
<BuildableReference
|
<BuildableReference
|
||||||
BuildableIdentifier = "primary"
|
BuildableIdentifier = "primary"
|
||||||
|
|||||||
@@ -535,4 +535,39 @@
|
|||||||
[loader waitForResponse];
|
[loader waitForResponse];
|
||||||
assertThat([loader.response bodyAsString], is(equalTo(@"{\"username\":\"hello\",\"password\":\"password\"}")));
|
assertThat([loader.response bodyAsString], is(equalTo(@"{\"username\":\"hello\",\"password\":\"password\"}")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)itShouldSetAnEmptyContentBodyWhenParamsIsNil {
|
||||||
|
RKClient* client = RKSpecNewClient();
|
||||||
|
client.cachePolicy = RKRequestCachePolicyNone;
|
||||||
|
RKSpecStubNetworkAvailability(YES);
|
||||||
|
RKSpecResponseLoader* loader = [RKSpecResponseLoader responseLoader];
|
||||||
|
loader.timeout = 20;
|
||||||
|
RKRequest* request = [client get:@"/echo_params" delegate:loader];
|
||||||
|
[loader waitForResponse];
|
||||||
|
assertThat([request.URLRequest valueForHTTPHeaderField:@"Content-Length"], is(equalTo(@"0")));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)itShouldSetAnEmptyContentBodyWhenQueryParamsIsAnEmptyDictionary {
|
||||||
|
RKClient* client = RKSpecNewClient();
|
||||||
|
client.cachePolicy = RKRequestCachePolicyNone;
|
||||||
|
RKSpecStubNetworkAvailability(YES);
|
||||||
|
RKSpecResponseLoader* loader = [RKSpecResponseLoader responseLoader];
|
||||||
|
loader.timeout = 20;
|
||||||
|
RKRequest* request = [client get:@"/echo_params" queryParams:[NSDictionary dictionary] delegate:loader];
|
||||||
|
[loader waitForResponse];
|
||||||
|
assertThat([request.URLRequest valueForHTTPHeaderField:@"Content-Length"], is(equalTo(@"0")));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)itShouldPUTWithParams {
|
||||||
|
RKClient* client = RKSpecNewClient();
|
||||||
|
RKParams *params = [RKParams params];
|
||||||
|
[params setValue:@"ddss" forParam:@"username"];
|
||||||
|
[params setValue:@"aaaa@aa.com" forParam:@"email"];
|
||||||
|
RKLogConfigureByName("RestKit/Network*", RKLogLevelTrace);
|
||||||
|
RKSpecResponseLoader* loader = [RKSpecResponseLoader responseLoader];
|
||||||
|
[client put:@"/ping" params:params delegate:loader];
|
||||||
|
[loader waitForResponse];
|
||||||
|
assertThat([loader.response bodyAsString], is(equalTo(@"{\"username\":\"ddss\",\"email\":\"aaaa@aa.com\"}")));
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -190,4 +190,40 @@
|
|||||||
assertThat(human.name, is(equalTo(@"My Name")));
|
assertThat(human.name, is(equalTo(@"My Name")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)itShouldNotSetAContentBodyOnAGET {
|
||||||
|
RKObjectManager* objectManager = RKSpecNewObjectManager();
|
||||||
|
[objectManager.router routeClass:[RKObjectMapperSpecModel class] toResourcePath:@"/humans/1"];
|
||||||
|
|
||||||
|
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[RKObjectMapperSpecModel class]];
|
||||||
|
[mapping mapAttributes:@"name", @"age", nil];
|
||||||
|
[objectManager.mappingProvider registerMapping:mapping withRootKeyPath:@"human"];
|
||||||
|
|
||||||
|
RKSpecResponseLoader* responseLoader = [RKSpecResponseLoader responseLoader];
|
||||||
|
RKObjectMapperSpecModel* human = [[RKObjectMapperSpecModel new] autorelease];
|
||||||
|
human.name = @"Blake Watters";
|
||||||
|
human.age = [NSNumber numberWithInt:28];
|
||||||
|
RKObjectLoader* loader = [objectManager getObject:human delegate:responseLoader];
|
||||||
|
[responseLoader waitForResponse];
|
||||||
|
RKLogCritical(@"%@", [loader.URLRequest allHTTPHeaderFields]);
|
||||||
|
assertThat([loader.URLRequest valueForHTTPHeaderField:@"Content-Length"], is(equalTo(@"0")));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)itShouldNotSetAContentBodyOnADELETE {
|
||||||
|
RKObjectManager* objectManager = RKSpecNewObjectManager();
|
||||||
|
[objectManager.router routeClass:[RKObjectMapperSpecModel class] toResourcePath:@"/humans/1"];
|
||||||
|
|
||||||
|
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[RKObjectMapperSpecModel class]];
|
||||||
|
[mapping mapAttributes:@"name", @"age", nil];
|
||||||
|
[objectManager.mappingProvider registerMapping:mapping withRootKeyPath:@"human"];
|
||||||
|
|
||||||
|
RKSpecResponseLoader* responseLoader = [RKSpecResponseLoader responseLoader];
|
||||||
|
RKObjectMapperSpecModel* human = [[RKObjectMapperSpecModel new] autorelease];
|
||||||
|
human.name = @"Blake Watters";
|
||||||
|
human.age = [NSNumber numberWithInt:28];
|
||||||
|
RKObjectLoader* loader = [objectManager deleteObject:human delegate:responseLoader];
|
||||||
|
[responseLoader waitForResponse];
|
||||||
|
RKLogCritical(@"%@", [loader.URLRequest allHTTPHeaderFields]);
|
||||||
|
assertThat([loader.URLRequest valueForHTTPHeaderField:@"Content-Length"], is(equalTo(@"0")));
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -95,6 +95,12 @@ class RestKit::SpecServer < Sinatra::Base
|
|||||||
{ :firstUser => {}, :secondUser => {}}.to_json
|
{ :firstUser => {}, :secondUser => {}}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
put '/ping' do
|
||||||
|
status 200
|
||||||
|
content_type 'application/json'
|
||||||
|
params.to_json
|
||||||
|
end
|
||||||
|
|
||||||
# start the server if ruby file executed directly
|
# start the server if ruby file executed directly
|
||||||
run! if app_file == $0
|
run! if app_file == $0
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user