示例#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
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);
}