PassRefPtr<FormData> httpBodyFromRequest(CFURLRequestRef request)
{
 //   RetainPtr<CFDataRef> bodyData(AdoptCF, CFURLRequestCopyHTTPRequestBody(request)); //Ricardo: comentando y cambiando por la linea siguiente.
    RetainPtr<CFDataRef> bodyData(AdoptCF, 0);

    if (bodyData)
        return FormData::create(CFDataGetBytePtr(bodyData.get()), CFDataGetLength(bodyData.get()));

    RetainPtr<CFArrayRef> bodyParts(AdoptCF, wkCFURLRequestCopyHTTPRequestBodyParts(request));
    if (bodyParts) {
        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();
    }

    // FIXME: what to do about arbitrary body streams?
    return 0;
}
Esempio n. 2
0
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;
}