ConnStateData::borrowPinnedConnection(HttpRequest *request, const AccessLogEntryPointer &ale)
{
    debugs(33, 7, pinning.serverConnection);
    Must(request);

    const auto pinningError = [&](const err_type type) {
        unpinConnection(true);
        HttpRequestPointer requestPointer = request;
        return ErrorState::NewForwarding(type, requestPointer, ale);
    };

    if (!Comm::IsConnOpen(pinning.serverConnection))
        throw pinningError(ERR_ZERO_SIZE_OBJECT);

    if (pinning.auth && pinning.host && strcasecmp(pinning.host, request->url.host()) != 0)
        throw pinningError(ERR_CANNOT_FORWARD); // or generalize ERR_CONFLICT_HOST

    if (pinning.port != request->url.port())
        throw pinningError(ERR_CANNOT_FORWARD); // or generalize ERR_CONFLICT_HOST

    if (pinning.peer && !cbdataReferenceValid(pinning.peer))
        throw pinningError(ERR_ZERO_SIZE_OBJECT);

    if (pinning.peerAccessDenied)
        throw pinningError(ERR_CANNOT_FORWARD); // or generalize ERR_FORWARDING_DENIED

    stopPinnedConnectionMonitoring();
    return pinning.serverConnection;
}
ConnStateData::borrowPinnedConnection(HttpRequest *request, const AccessLogEntryPointer &ale)
{
    debugs(33, 7, pinning.serverConnection);
    Must(request);

    const auto pinningError = [&](const err_type type) {
        unpinConnection(true);
        HttpRequestPointer requestPointer = request;
        return ErrorState::NewForwarding(type, requestPointer, ale);
    };

    if (!Comm::IsConnOpen(pinning.serverConnection))
        throw pinningError(ERR_ZERO_SIZE_OBJECT);

    if (pinning.auth && pinning.host && strcasecmp(pinning.host, request->url.host()) != 0)
        throw pinningError(ERR_CANNOT_FORWARD);  

    if (pinning.port != request->url.port())
        throw pinningError(ERR_CANNOT_FORWARD);  

    if (pinning.peer && !cbdataReferenceValid(pinning.peer))
        throw pinningError(ERR_ZERO_SIZE_OBJECT);

    if (pinning.peerAccessDenied)
        throw pinningError(ERR_CANNOT_FORWARD);  

    stopPinnedConnectionMonitoring();
    return pinning.serverConnection;
}