private static function addLocationHeaderToResponse(
        ResponseInterface $response,
        $locationMode
    ) {
        //If the response already has this header, return itself.
        if ($response->hasHeader(Resources::X_MS_CONTINUATION_LOCATION_MODE)) {
            return $response;
        }
        //Otherwise, add the header that indicates the endpoint to be used if
        //continuation token is used for subsequent request. Notice that if the
        //response does not have location header set at the moment, it means
        //that the user have not set a retry middleware.
        if ($locationMode == LocationMode::PRIMARY_THEN_SECONDARY) {
            $response = $response->withHeader(
                Resources::X_MS_CONTINUATION_LOCATION_MODE,
                LocationMode::PRIMARY_ONLY
            );
        } elseif ($locationMode == LocationMode::SECONDARY_THEN_PRIMARY) {
            $response = $response->withHeader(
                Resources::X_MS_CONTINUATION_LOCATION_MODE,
                LocationMode::SECONDARY_ONLY
            );
        } elseif ($locationMode == LocationMode::SECONDARY_ONLY  ||
                  $locationMode == LocationMode::PRIMARY_ONLY) {
            $response = $response->withHeader(
                Resources::X_MS_CONTINUATION_LOCATION_MODE,
                $locationMode
            );
        }
        return $response;
    }