Edit before posting: my result didn't match with the solution, found the error while posting, figured I would post it anyway because someone else might find it useful
I'm trying to solve:
$$\int_{0}^{\infty}\frac{\cos z}{z^2 + 1}=\frac{1}{2}\int_{-\infty}^{\infty}\frac{\cos z}{z^2 + 1}$$
I'm using the usual contour, a semi circle $\gamma$ in the upper plane, so that:
$$2\pi i\sum_{Im(z)>0} Res(\frac{e^{iz}}{z^2+1},z)=\int_{\gamma}\frac{e^{iz}}{z^2+1}=\int_{-\infty}^{\infty}\frac{e^{iz}}{z^2+1}=\int_{-\infty}^{\infty}\frac{\cos z}{z^2 + 1}+i\int_{-\infty}^{\infty}\frac{\sin z}{z^2 + 1}$$
Since $\int_{-\infty}^{\infty}\frac{\cos x}{x^2 + 1}$ is real valued, it's value is the real part of $\int_{\gamma}\frac{e^{iz}}{z^2+1}$, actually, $\int_{-\infty}^{\infty}\frac{\sin z}{z^2 + 1}=0$ since $\sin z$ is odd and $\frac{1}{z^2+1}$ is even if $z\in \mathbb R$.
Therefore $$\int_{0}^{\infty}\frac{\cos z}{z^2 + 1}=\frac{1}{2}\int_{-\infty}^{\infty}\frac{\cos z}{z^2 + 1}=\frac{1}{2} Res(\frac{e^{iz}}{z^2+1},i),$$ since $-i$ is not inside the contour.
$$Res(\frac{e^{iz}}{z^2+1},i)=\lim_{z \rightarrow i} (z-i)\frac{e^{iz}}{z^2+1}=\lim_{z \rightarrow i} \frac{e^{iz}}{z+i}=\frac{1}{2ie}$$
Substituting we get:
$$\int_{0}^{\infty}\frac{\cos z}{z^2 + 1}=\frac{\pi}{2e}$$