In the text "Function Theory of One Complex Variable" Third Edition by Robert E.Greene and Steven G.Krantz I'm having trouble understanding the steps to analyze $(1)$. When the author defines the integrand on the contour $\gamma_{R}$, why isn't it considered to use the Residue Theorem when $f(z) = \frac{e^{ix}e^{-y}+e^{-ix} e^{y}}{1 + z^{2}}$ ?
$(1)$
$$\int_{-\infty}^{\infty} \frac{cos(x)}{1+x^{2}} $$
$\text{Proof}$
For our analysis of $(1)$, the author at first considers that $f(z) = \frac{e^{ix}e^{-y}+e^{-ix} e^{y}}{1 + z^{2}}.$ But instead changes $f(z)$ due to the fact that one needs good estimates to result. So for the rest of the proceeding proof he considers that $g(z) = \frac{e^{iz}}{(1+z^{2})}$.
On one hand for $R > 1$ one can notation that,
$$\oint_{\gamma_{R}}g(z) = 2 \pi i \cdot Res_{g}(i) \cdot Ind_{\gamma_{R}}(I) = 2 \pi i \bigg( \frac{1}{2 ei } \bigg) = \pi / e.$$
On the other hand with $\gamma_{R}^{1} = t$, $-R \leq t \leq R,$ and $\gamma_{R}^{2}(t) = Re^{it}$, $0 \leq t \leq \pi$, we have
$$\oint_{\gamma_{R}}g(z)~ dz = \oint_{\gamma_{R}^{1}} g(z) dz+ \oint_{\gamma_{R}^{2}}g(z) ~dz$$
It's obvious that to notion that
$$\oint_{\gamma_{R}^{1}} g(z) dz \rightarrow \int_{-\infty}^{\infty} \frac{e^{ix}}{1+x^{2}}.$$
It becomes natural to claim that
$$\lim_{R \rightarrow \infty}\bigg | \oint_{\gamma_{R}^{2}}g(z) dz \bigg| \rightarrow 0. $$
Using the Estimation Lemma one can see that,
$$\bigg |\oint_{\gamma_{R}^{2}} g(z) dz \bigg | \leq \big\{\text{length}(\gamma_{R}^{2}) \big\} \cdot \sup_{\gamma_{R}^{2}}|g(z)|\leq \pi \cdot \frac{1}{R^{2} - 1}. $$
Thus,
$$\int_{-\infty}^{\infty} \frac{cos(x)}{1+x^{2}} = Re \int_{-\infty}^{\infty} \frac{e^{ix}}{1+x^{2}} = Re(\pi /e) = \pi / e$$
In conclusion, for $R> 1$ why doesn't the author consider for $ f(z) = \frac{e^{ix}e^{-y}+e^{-ix} e^{y}}{1 + z^{2}}$ that
$$\oint_{\gamma_{R}} \frac{e^{ix}e^{-y}+e^{-ix} e^{y}}{1 + z^{2}} = 2 \pi i \sum_{j} Ind{\gamma}(P{j}) \cdot Res_{f}(P_{j}) $$
The integral around a closed contour, with the original $f$ rather than the modified $g$, can indeed be evaluated by using the residue theorem, but that doesn't seem to help with the original problem of calculating the integral along the real axis, which is not a closed contour. To connect the original problem with the residue calculation, you need to close the contour, which is usually done by taking a long segment of the real line (from $-R$ to $R$ in your question) and closing it with a big semicircle in the upper or lower half-plane. And then you have to show that the integral over the semicircle is small (or otherwise under good control) so that you can infer a result about the integral along just the real axis. With the original $f$, this kind of control seems to be lacking, because the cosine function, though nice and bounded along the real axis, blows up badly when you get far above or far below the real axis in the complex plane.
Fortunately, one can (and the authors do) dodge the problem by noticing that $e^{iz}$ is bounded in the upper half-plane. So the residue calculation works if we have $e^{iz}$ instead of $\cos z$ in the numerator, and then we can get the answer for $\cos z$ by noticing that, along the original domain of integration, the real axis, it's the real part of $e^{iz}$.