void StartDestroyStreamChild(const PCacheResponse& aResponse) { if (aResponse.body().type() == PCacheReadStreamOrVoid::Tvoid_t) { return; } StartDestroyStreamChild(aResponse.body().get_PCacheReadStream()); }
void AddFeatureToStreamChild(const PCacheResponse& aResponse, Feature* aFeature) { if (aResponse.body().type() == PCacheReadStreamOrVoid::Tvoid_t) { return; } AddFeatureToStreamChild(aResponse.body().get_PCacheReadStream(), aFeature); }
void TypeUtils::ToPCacheResponseWithoutBody(PCacheResponse& aOut, InternalResponse& aIn, ErrorResult& aRv) { aOut.type() = aIn.Type(); nsAutoCString url; aIn.GetUrl(url); CopyUTF8toUTF16(url, aOut.url()); if (aOut.url() != EmptyString()) { // Pass all Response URL schemes through... The spec only requires we take // action on invalid schemes for Request objects. ProcessURL(aOut.url(), nullptr, nullptr, aRv); if (aRv.Failed()) { return; } } aOut.status() = aIn.GetStatus(); aOut.statusText() = aIn.GetStatusText(); nsRefPtr<InternalHeaders> headers = aIn.Headers(); MOZ_ASSERT(headers); headers->GetPHeaders(aOut.headers()); aOut.headersGuard() = headers->Guard(); }
void TypeUtils::ToPCacheResponse(PCacheResponse& aOut, Response& aIn, ErrorResult& aRv) { if (aIn.BodyUsed()) { aRv.ThrowTypeError(MSG_FETCH_BODY_CONSUMED_ERROR); return; } nsRefPtr<InternalResponse> ir = aIn.GetInternalResponse(); ToPCacheResponseWithoutBody(aOut, *ir, aRv); nsCOMPtr<nsIInputStream> stream; aIn.GetBody(getter_AddRefs(stream)); if (stream) { aIn.SetBodyUsed(); } SerializeCacheStream(stream, &aOut.body(), aRv); if (NS_WARN_IF(aRv.Failed())) { return; } }
already_AddRefed<Response> TypeUtils::ToResponse(const PCacheResponse& aIn) { nsRefPtr<InternalResponse> ir; switch (aIn.type()) { case ResponseType::Error: ir = InternalResponse::NetworkError(); break; case ResponseType::Opaque: ir = InternalResponse::OpaqueResponse(); break; case ResponseType::Default: ir = new InternalResponse(aIn.status(), aIn.statusText()); break; case ResponseType::Basic: { nsRefPtr<InternalResponse> inner = new InternalResponse(aIn.status(), aIn.statusText()); ir = InternalResponse::BasicResponse(inner); break; } case ResponseType::Cors: { nsRefPtr<InternalResponse> inner = new InternalResponse(aIn.status(), aIn.statusText()); ir = InternalResponse::CORSResponse(inner); break; } default: MOZ_CRASH("Unexpected ResponseType!"); } MOZ_ASSERT(ir); ir->SetUrl(NS_ConvertUTF16toUTF8(aIn.url())); nsRefPtr<InternalHeaders> internalHeaders = new InternalHeaders(aIn.headers(), aIn.headersGuard()); ErrorResult result; ir->Headers()->SetGuard(aIn.headersGuard(), result); MOZ_ASSERT(!result.Failed()); ir->Headers()->Fill(*internalHeaders, result); MOZ_ASSERT(!result.Failed()); nsCOMPtr<nsIInputStream> stream = ReadStream::Create(aIn.body()); ir->SetBody(stream); nsRefPtr<Response> ref = new Response(GetGlobalObject(), ir); return ref.forget(); }