Skip to content

Commit fc15954

Browse files
committed
Allow sending array buffers for XMLHttpRequest; close phoboslab#531
1 parent 96dc576 commit fc15954

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Source/Ejecta/EJUtils/EJBindingHttpRequest.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,17 @@ - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
232232
[request setValue:requestHeaders[header] forHTTPHeaderField:header];
233233
}
234234

235+
// Set body data (Typed Array or String)
235236
if( argc > 0 ) {
236-
NSString *requestBody = JSValueToNSString( ctx, argv[0] );
237-
NSData *requestData = [NSData dataWithBytes:[requestBody UTF8String] length:[requestBody length]];
238-
[request setHTTPBody:requestData];
237+
if( JSTypedArrayGetType(ctx, argv[0]) != kJSTypedArrayTypeNone ) {
238+
size_t length = 0;
239+
void *data = JSTypedArrayGetDataPtr(ctx, argv[0], &length);
240+
request.HTTPBody = [NSData dataWithBytes:data length:length];
241+
}
242+
else {
243+
NSString *requestBody = JSValueToNSString( ctx, argv[0] );
244+
request.HTTPBody = [requestBody dataUsingEncoding:NSUTF8StringEncoding];
245+
}
239246
}
240247

241248
if( timeout ) {

0 commit comments

Comments
 (0)