Пример #1
0
Request* Request::clone(ExceptionState& exceptionState) const
{
    if (bodyUsed()) {
        exceptionState.throwTypeError("Request body is already used");
        return nullptr;
    }

    FetchRequestData* request = m_request->clone();
    if (blobDataHandle() && isBodyConsumed()) {
        // Currently the only methods that can consume body data without
        // setting 'body passed' flag consume entire body (e.g. text()). Thus
        // we can set an empty blob to the new request instead of creating a
        // draining stream.
        // TODO(yhirano): Fix this once Request.body is introduced.
        OwnPtr<BlobData> blobData = BlobData::create();
        blobData->setContentType(blobDataHandle()->type());
        request->setBlobDataHandle(BlobDataHandle::create(blobData.release(), 0));
    }

    Headers* headers = Headers::create(request->headerList());
    headers->setGuard(m_headers->guard());
    Request* r = new Request(executionContext(), request, headers);
    r->suspendIfNeeded();
    return r;
}
Пример #2
0
ScriptPromise Body::rejectInvalidConsumption(ScriptState* scriptState)
{
    if (m_opaque)
        return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(scriptState->isolate(), "The body is opaque."));
    if (bodyUsed())
        return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(scriptState->isolate(), "Already read"));
    return ScriptPromise();
}
Пример #3
0
Response* Response::clone(ExceptionState& exceptionState)
{
    if (isBodyLocked() || bodyUsed()) {
        exceptionState.throwTypeError("Response body is already used");
        return nullptr;
    }

    FetchResponseData* response = m_response->clone(executionContext());
    Headers* headers = Headers::create(response->headerList());
    headers->setGuard(m_headers->guard());
    return new Response(executionContext(), response, headers);
}
Пример #4
0
ScriptPromise Body::text(ScriptState* scriptState)
{
    if (bodyUsed())
        return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(scriptState->isolate(), "Already read"));

    // See above comment.
    if (!scriptState->executionContext())
        return ScriptPromise();

    ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
    ScriptPromise promise = resolver->promise();
    bodyBuffer()->startLoading(scriptState->executionContext(), FetchDataLoader::createLoaderAsString(), new BodyTextConsumer(resolver));
    return promise;
}
Пример #5
0
ScriptPromise Body::arrayBuffer(ScriptState* scriptState)
{
    if (bodyUsed())
        return ScriptPromise::reject(scriptState, V8ThrowException::createTypeError(scriptState->isolate(), "Already read"));

    // When the main thread sends a V8::TerminateExecution() signal to a worker
    // thread, any V8 API on the worker thread starts returning an empty
    // handle. This can happen in Body::readAsync. To avoid the situation, we
    // first check the ExecutionContext and return immediately if it's already
    // gone (which means that the V8::TerminateExecution() signal has been sent
    // to this worker thread).
    if (!scriptState->executionContext())
        return ScriptPromise();

    ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
    ScriptPromise promise = resolver->promise();
    bodyBuffer()->startLoading(scriptState->executionContext(), FetchDataLoader::createLoaderAsArrayBuffer(), new BodyArrayBufferConsumer(resolver));
    return promise;
}
Пример #6
0
FetchRequestData* Request::passRequestData()
{
    ASSERT(!bodyUsed());
    lockBody(PassBody);
    return m_request->pass();
}