I am trying to calculate $$I=\int_0^{\pi}\frac {\cos {n \theta}}{1-2r\cos \theta+r^2}\, \mathrm d \theta$$ where $r\in(0,1)$
I tried substituting $u = e^{2 i \theta}$ and using the Cauchy integral formula:
\begin{align}I&=\Re \int_{|u|=1}\frac {u^{n/2}}{(r-u^{1/2})(r-u^{-1/2})}\frac 1 {2iu} \,\mathrm d u \\&=\Re \frac {i} {2}\int_{|u|=1} \frac {u^{n/2 - 1}(r+u^{1/2})}{(u-r^2)(r-u^{-1/2})}\, \mathrm d u \\ &=\frac {2 \pi r^{n}}{1-r^2} \end{align}
but the correct answer is $\dfrac {\pi r^n}{1-r^2}$
Where did I make a mistake?