Finding $\int _{-\infty }^{\infty }\frac{e^x\,dx}{1\:+\:e^{4x}}$ with residue integration This integral was given as part of an exam in complex analysis. Here we are first asked to take the contour integral of the rectangle below.

This is computed by finding the poles:
$$z\:=\:\frac{1}{4}\left(i\pi \:+\:i2\pi c_1\right),\:c_1\in \mathbb{Z}
$$
Only $iπ/4$ and $i3π/4$ are inside the contour and we proceed to find the solution of the contour integral:
$$\frac{\pi \sqrt{2}}{2}$$
This is fine, however, when asked to compute the real integral (task c) in the linked picture), I struggle to understand how we rigorously can be sure that
$$ \frac{\pi \sqrt{2}}{4}$$
is the correct answer. This leads to my question:
Q. Could I reach the same result by instead using the "standard" semicircle in the upper half-plane, and let the radius $R$ approach infinity. Or is this an integral where I need to choose a different geometric contour to reach the correct answer? If so, how do I proceed to find the correct contour in a similar situation where I am not given the shape beforehand?

I am puzzled because the integral has four poles in the unit circle, but if we instead look at the imaginary axis, it has an infinite number of poles when the radius approaches infinity.
 A: The integral along the top horizontal side is
$$\int_M^{-M} \frac{e^{x+\pi i}}{1+e^{4(x+\pi i)}}dx=\int_{-M}^M\frac{e^x}{1+e^{4x}}dx$$
Therefore the result is exactly half of the contour integral.
It won't be easy to do it with the semi-circle contour. For one thing, it will enclose more and more singularities.
A: With the substitution $e^x=t$, $e^xdx=dt$, the integral, considering the integrand is now an even function, becomes:
$$\int_0^\infty \frac{dt}{1+t^4}=\frac{1}{2}\int_{-\infty}^\infty \frac{dx}{1+x^4}\;.$$
Now
$$f(z)\equiv \frac{1}{1+z^4}$$
has four poles, only two of which fall inside the upper semicircle, namely $z_1=e^{πi/4}$ and $z_2=e^{3πi/4}$. Therefore, you only need to evaluate the residues of $f(z)$ at those two poles.
By differentiation you will quickly find that
$$Res(f,z_1)+Res(f,z_2)=\frac{1}{4}\left(\frac{1}{z_1^3}+\frac{1}{z_2^3}\right)\;.$$
The integral on the upper semicircle can be easily shown to approach $0$ as $R\to \infty$, so if you put all the above results together and use the residue theorem you get the expected result of $\frac{π}{2\sqrt{2}}$.
I hope this answers your question.
