Always set Access-Control-Allow-Origin on response

Error responses were not having this set, which obscured the true error from the client.
This commit is contained in:
Scott Kyle 2015-10-15 03:01:34 -07:00
parent 94521b73bb
commit 18f97b6ec1
1 changed files with 9 additions and 5 deletions

View File

@ -79,12 +79,16 @@ static id s_executor;
NSError *error;
NSData *data = [(GCDWebServerDataRequest *)request data];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if (error) {
NSLog(@"%@", error);
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_UnprocessableEntity underlyingError:error message:@"Invalid RPC request"];
GCDWebServerResponse *response;
if (error || ![json isKindOfClass:[NSDictionary class]]) {
NSLog(@"Invalid RPC request - %@", error ?: json);
response = [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_UnprocessableEntity underlyingError:error message:@"Invalid RPC request"];
}
GCDWebServerDataResponse *response = [GCDWebServerDataResponse responseWithJSONObject:[rpcServer performRequest:request.path args:json]];
else {
response = [GCDWebServerDataResponse responseWithJSONObject:[rpcServer performRequest:request.path args:json]];
}
[response setValue:@"http://localhost:8081" forAdditionalHeader:@"Access-Control-Allow-Origin"];
return response;
}];