Esempio n. 1
0
CFURLRequestRef ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest(CFURLRequestRef cfRequest, CFURLResponseRef originalRedirectResponse)
{
    // If the protocols of the new request and the current request match, this is not an HSTS redirect and we don't need to synthesize a redirect response.
    if (!originalRedirectResponse) {
        RetainPtr<CFStringRef> newScheme = adoptCF(CFURLCopyScheme(CFURLRequestGetURL(cfRequest)));
        if (CFStringCompare(newScheme.get(), m_originalScheme.get(), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
            CFRetain(cfRequest);
            return cfRequest;
        }
    }

    RefPtr<ResourceHandleCFURLConnectionDelegateWithOperationQueue> protector(this);

    dispatch_async(dispatch_get_main_queue(), ^{
        if (!protector->hasHandle()) {
            continueWillSendRequest(nullptr);
            return;
        }

        LOG(Network, "CFNet - ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest(handle=%p) (%s)", m_handle, m_handle->firstRequest().url().string().utf8().data());

        RetainPtr<CFURLResponseRef> redirectResponse = synthesizeRedirectResponseIfNecessary(cfRequest, originalRedirectResponse);
        ASSERT(redirectResponse);

        ResourceRequest request = createResourceRequest(cfRequest, redirectResponse.get());
        m_handle->willSendRequest(request, redirectResponse.get());
    });
CFURLRequestRef ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest(CFURLRequestRef cfRequest, CFURLResponseRef originalRedirectResponse)
{
    // If the protocols of the new request and the current request match, this is not an HSTS redirect and we don't need to synthesize a redirect response.
    if (!originalRedirectResponse) {
        RetainPtr<CFStringRef> newScheme = adoptCF(CFURLCopyScheme(CFURLRequestGetURL(cfRequest)));
        if (CFStringCompare(newScheme.get(), m_originalScheme.get(), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
            CFRetain(cfRequest);
            return cfRequest;
        }
    }

    ASSERT(!isMainThread());

    // FIXME: The block implicitly copies protector object, which is wasteful. We should just call ref(),
    // capture "this" by pointer value, and use a C++ lambda to prevent other unintentional capturing.
    RefPtr<ResourceHandleCFURLConnectionDelegateWithOperationQueue> protectedThis(this);

    dispatch_async(dispatch_get_main_queue(), ^{
        if (!protectedThis->hasHandle()) {
            continueWillSendRequest(nullptr);
            return;
        }

        LOG(Network, "CFNet - ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest(handle=%p) (%s)", m_handle, m_handle->firstRequest().url().string().utf8().data());

        RetainPtr<CFURLResponseRef> redirectResponse = synthesizeRedirectResponseIfNecessary(cfRequest, originalRedirectResponse);
        ASSERT(redirectResponse);

        ResourceRequest request = createResourceRequest(cfRequest, redirectResponse.get());
        m_handle->willSendRequest(request, redirectResponse.get());
    });
CFURLRequestRef ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest(CFURLRequestRef cfRequest, CFURLResponseRef originalRedirectResponse)
{
    RefPtr<ResourceHandleCFURLConnectionDelegateWithOperationQueue> protector(this);

    dispatch_async(dispatch_get_main_queue(), ^{
        if (!protector->hasHandle()) {
            continueWillSendRequest(nullptr);
            return;
        }

        LOG(Network, "CFNet - ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest(handle=%p) (%s)", m_handle, m_handle->firstRequest().url().string().utf8().data());

        RetainPtr<CFURLResponseRef> redirectResponse = synthesizeRedirectResponseIfNecessary(cfRequest, originalRedirectResponse);
        if (!redirectResponse) {
            m_handle->continueWillSendRequest(cfRequest);
            return;
        }

        ResourceRequest request = createResourceRequest(cfRequest, redirectResponse.get());
        m_handle->willSendRequest(request, redirectResponse.get());
    });
CFURLRequestRef SynchronousResourceHandleCFURLConnectionDelegate::willSendRequest(CFURLRequestRef cfRequest, CFURLResponseRef originalRedirectResponse)
{
    RetainPtr<CFURLResponseRef> redirectResponse = synthesizeRedirectResponseIfNecessary(cfRequest, originalRedirectResponse);

    if (!redirectResponse) {
        CFRetain(cfRequest);
        return cfRequest;
    }

    LOG(Network, "CFNet - SynchronousResourceHandleCFURLConnectionDelegate::willSendRequest(handle=%p) (%s)", m_handle, m_handle->firstRequest().url().string().utf8().data());

    ResourceRequest request = createResourceRequest(cfRequest, redirectResponse.get());
    auto newRequest = m_handle->willSendRequest(WTFMove(request), redirectResponse.get());

    if (newRequest.isNull())
        return nullptr;

    auto newCFRequest = newRequest.cfURLRequest(UpdateHTTPBody);

    CFRetain(newCFRequest);
    return newCFRequest;
}