static void asynchttp_timer_proc(asynchttp_t *http) {
    CFStringRef req_meth = http->request ? CFHTTPMessageCopyRequestMethod(http->request) : NULL;
    CFURLRef req_url = http->request ? CFHTTPMessageCopyRequestURL(http->request) : NULL;
    secnotice("http", "Timeout during %@ %@.", req_meth, req_url);
    CFReleaseSafe(req_url);
    CFReleaseSafe(req_meth);
    asynchttp_complete(http);
}
Пример #2
0
CRESTRequestRef CRESTRequestCreateWithBytes(UInt8 const *bytes, ssize_t len)
{
	CFURLRef url;
	CRESTRequestRef request;
	CFHTTPMessageRef message;

	message	= CFHTTPMessageCreateEmpty(kCFAllocatorDefault, true);
	request = calloc(1, sizeof(struct CRESTRequest));
	assert(request);
	bool isAppended = CFHTTPMessageAppendBytes(message, bytes, (CFIndex) len);
	bool isComplete = CFHTTPMessageIsHeaderComplete(message);

	if( ! ( isAppended && isComplete ) )
	{
		CFRelease(message);
		CRESTRequestDealloc(request);
		return NULL;
	}

	url = CFHTTPMessageCopyRequestURL(message);

	CFMutableDictionaryRef params = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks,
			&kCFTypeDictionaryValueCallBacks);

	CFStringRef query = CFURLCopyQueryString(url, NULL);
	if( query )
	{
		parseParams(params, query);
		CFRelease(query);
	}

	CFDataRef bodyData = CFHTTPMessageCopyBody(message);
	if( CFDataGetLength(bodyData) )
	{
		CFStringRef bodyString = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, bodyData,
				kCFStringEncodingUTF8);
		parseParams(params, bodyString);
		CFRelease(bodyString);
	}
	CFRelease(bodyData);

	request->method = CFHTTPMessageCopyRequestMethod(message);
	request->path = CFURLCopyPath(url);
	request->params = (CFDictionaryRef) params;

	CFRelease(url);
	CFRelease(message);

	return request;
}