I am trying to evaluate this definite integral problem. $$\int_0^\pi\frac{\mathrm dx}{1+\cos^2x}$$
Dividing the numerator and the denominator by $\cos^2x$, the integrand becomes $$\int_0^\pi\frac{\sec^2x\,\mathrm dx}{\sec^2x+1}=\int_0^\pi\frac{\sec^2x\mathrm dx}{\tan^2x+2}$$
Now with the substitution $u=\tan x$, the definite integral reduces to $$\int_0^0\frac{\mathrm du}{u^2+2}=0?$$
But using the property of definite integrals we know, $$\int_0^{2a}f(x)\mathrm dx=\int_0^a(f(x)+f(2a-x))\mathrm dx$$
Applying this property to our function, the integral becomes $$2\int_0^\frac\pi2\frac{\sec^2x\,\mathrm dx}{\tan^2x+2}\mathrm dx=2\int_0^\infty\frac{\mathrm du}{u^2+2}=\frac{\pi}{\sqrt{2}} \ !!$$
Getting different answers in both cases. What am I doing wrong?