Evaluate the improper integral with residues. 
$$\int_0^{\infty} \frac{x^2+1}{x^4+1}dx$$

What i've found are the singularities at: $e^{\pi/4+\pi/2n}$ for $n=0,1,2,3$. But i'm unsure how to calculate the integral since I don't want to include the singularity at $x_2=\frac{-1+i}{\sqrt{2}}$ since then I would be calculating the integral from negative to positive infinity. 
My idea was to construct a contour $\gamma : x=ti$ where $R<t\leq0$ and $\lim_{R\rightarrow \infty}$. My reckoning was that since: 
$$\int_{\gamma}\frac{x^2+1}{x^4+1}dx=i\int_R^0\frac{1-t^2}{t^4+1}dt$$
doesn't have any singularities along the positive real numberline, it is therefore bounded and thus: 
$$i\int_R^0\frac{1-t^2}{t^4+1}dt\leq \Big| i\int_R^0\frac{1-t^2}{t^4+1}dt\Big|\leq\int_R^0\frac{|1-t^2|}{|t^4+1|}dt\leq\frac{|R^2|+1}{|R^4|-1}\rightarrow0 \text{ when } R\rightarrow \infty.$$
The answer would then be: 
$$\lim_{R\rightarrow \infty}\int_0^{R}\frac{x^2+1}{x^4+1}dx=2\pi iRes(f;e^{\pi/4})-\int_0^{\pi/2}f(x)dx-i\int_R^0f(x)dx=\frac{\pi}{2\sqrt{2}}.$$
But sadly I am mistaken, what is wrong?

Let $I$ be the integral defined by
$$I=\int_0^\infty\frac{x^2+1}{x^4+1}\,dx \tag 1$$
We proceed to evaluate the integral in $(1)$ by analyzing the contour integral $J$
$$J=\oint_C \frac{z^2+1}{z^4+1}\,dz$$
where $C$ is the quarter circle in the first quadrant, centered at the origin, with radius $R$.  Then, we have
$$J=\int_0^R \frac{x^2+1}{x^4+1}\,dx+i\int_0^R \frac{y^2-1}{y^4+1}\,dy+\int_0^{\pi/2}\frac{R^2e^{i2\phi}+1}{R^4e^{i4\phi}+1}\,iRe^{i\phi}\,d\phi \tag 2$$
From the residue theorem, we find that 
$$\begin{align}
J&=2\pi i \text{Res}\left(\frac{z^2+1}{z^4+1}, z=e^{i\pi/4}\right)\\\\
&=2\pi i \frac{e^{i\pi/2}+1}{4e^{i3\pi/4}}\\\\
&=\frac{\sqrt{2}\pi}{2}
\end{align}$$
As $R\to \infty$, the third integral on the right-hand side of $(2)$ vanishes and we find
$$\int_0^\infty \frac{x^2+1}{x^4+1}\,dx+i\int_0^\infty \frac{y^2-1}{y^4+1}\,dy=\frac{\sqrt{2}\pi}{2} \tag 3$$
Equating the real parts of $(3)$, we find 
$$\bbox[5px,border:2px solid #C0A000]{\int_0^\infty \frac{x^2+1}{x^4+1}\,dx=\frac{\sqrt{2}\pi}{2}}$$ 
As a bonus, we find that 
$$\int_0^\infty \frac{x^2-1}{x^4+1}\,dx=0$$
which one can verify directly by enforcing the substitution $x\to 1/x$.
