void getResourceRequest(ResourceRequest& request, CFURLRequestRef cfRequest)
{
    request = ResourceRequest(CFURLRequestGetURL(cfRequest));

    request.setCachePolicy((ResourceRequestCachePolicy)CFURLRequestGetCachePolicy(cfRequest));
    request.setTimeoutInterval(CFURLRequestGetTimeoutInterval(cfRequest));
    request.setMainDocumentURL(KURL(CFURLRequestGetMainDocumentURL(cfRequest)));
    if (CFStringRef method = CFURLRequestCopyHTTPRequestMethod(cfRequest)) {
        request.setHTTPMethod(method);
        CFRelease(method);
    }
    request.setAllowHTTPCookies(CFURLRequestShouldHandleHTTPCookies(cfRequest));

    if (CFDictionaryRef headers = CFURLRequestCopyAllHTTPHeaderFields(cfRequest)) {
        CFIndex headerCount = CFDictionaryGetCount(headers);
        Vector<const void*, 128> keys(headerCount);
        Vector<const void*, 128> values(headerCount);
        CFDictionaryGetKeysAndValues(headers, keys.data(), values.data());
        for (int i = 0; i < headerCount; ++i)
            request.setHTTPHeaderField((CFStringRef)keys[i], (CFStringRef)values[i]);
        CFRelease(headers);
    }


    if (CFDataRef bodyData = CFURLRequestCopyHTTPRequestBody(cfRequest)) {
        request.setHTTPBody(new FormData(CFDataGetBytePtr(bodyData), CFDataGetLength(bodyData)));
        CFRelease(bodyData);
    } else if (CFReadStreamRef bodyStream = CFURLRequestCopyHTTPRequestBodyStream(cfRequest)) {
        if (FormData* formData = httpBodyFromStream(bodyStream))
            request.setHTTPBody(formData);
        CFRelease(bodyStream);
    }
    // FIXME: what to do about arbitrary body streams?
}
PassRefPtr<FormData> httpBodyFromRequest(CFURLRequestRef request)
{
    if (RetainPtr<CFDataRef> bodyData = CFURLRequestCopyHTTPRequestBody(request))
        return FormData::create(CFDataGetBytePtr(bodyData.get()), CFDataGetLength(bodyData.get()));

    if (wkCanAccessCFURLRequestHTTPBodyParts()) {
        if (RetainPtr<CFArrayRef> bodyParts = wkCFURLRequestCopyHTTPRequestBodyParts(request)) {
            RefPtr<FormData> formData = FormData::create();

            CFIndex count = CFArrayGetCount(bodyParts.get());
            for (CFIndex i = 0; i < count; i++) {
                CFTypeRef bodyPart = CFArrayGetValueAtIndex(bodyParts.get(), i);
                CFTypeID typeID = CFGetTypeID(bodyPart);
                if (typeID == CFStringGetTypeID()) {
                    String filename = (CFStringRef)bodyPart;
                    formData->appendFile(filename);
                } else if (typeID == CFDataGetTypeID()) {
                    CFDataRef data = (CFDataRef)bodyPart;
                    formData->appendData(CFDataGetBytePtr(data), CFDataGetLength(data));
                } else
                    ASSERT_NOT_REACHED();
            }
            return formData.release();
        }
    } else {
        if (RetainPtr<CFReadStreamRef> bodyStream = CFURLRequestCopyHTTPRequestBodyStream(request))
            return getStreamFormDatas().get(bodyStream.get());
    }

    // FIXME: what to do about arbitrary body streams?
    return 0;
}
JNIEXPORT jintLong JNICALL WebKit_win32_NATIVE(CFURLRequestCopyHTTPRequestBody)
	(JNIEnv *env, jclass that, jintLong arg0)
{
	jintLong rc = 0;
	WebKit_win32_NATIVE_ENTER(env, that, CFURLRequestCopyHTTPRequestBody_FUNC);
	rc = (jintLong)CFURLRequestCopyHTTPRequestBody((CFURLRequestRef)arg0);
	WebKit_win32_NATIVE_EXIT(env, that, CFURLRequestCopyHTTPRequestBody_FUNC);
	return rc;
}
void ResourceRequest::doUpdateResourceHTTPBody()
{
    if (!m_cfRequest) {
        m_httpBody = nullptr;
        return;
    }

    if (RetainPtr<CFDataRef> bodyData = adoptCF(CFURLRequestCopyHTTPRequestBody(m_cfRequest.get())))
        m_httpBody = FormData::create(CFDataGetBytePtr(bodyData.get()), CFDataGetLength(bodyData.get()));
    else if (RetainPtr<CFReadStreamRef> bodyStream = adoptCF(CFURLRequestCopyHTTPRequestBodyStream(m_cfRequest.get()))) {
        FormData* formData = httpBodyFromStream(bodyStream.get());
        // There is no FormData object if a client provided a custom data stream.
        // We shouldn't be looking at http body after client callbacks.
        ASSERT(formData);
        if (formData)
            m_httpBody = formData;
    }
}