How should I set the integral route for this complex integral? \begin{equation}
\int_0^{\infty} \dfrac{x^{\lambda -1}}{x^2+1} dx
=
\dfrac{\pi}{2 \sin{\dfrac{\pi \lambda}{2}}} \quad (0< \lambda < 2)
\end{equation}
I will prove this using complex integral, but I don't come up with how I should set the integral route.
I tried prove the equality using the integral route below and using residue theorem.
$
C_{R} : \text{semicircle in first and second quadrant whose radius is R }\\
C_1 : [-R, \epsilon]\\
C_{\epsilon} : \text{semicircle in first and second quadrant whose radius is $\epsilon$ }\\
C_2 : [\epsilon, R]
$
However, I failed to prove. It seems that it is impossible to calculate the integral with this integral route.
I would like you to teach me how I should set the integral route.
 A: One may use $\beta$ function.
$$I=\int_{0}^{\infty} \frac{x^{k-1}}{1+x^2} dx$$
Let $x=\tan t$, then
$$I=\int_{0}^{\pi/2} \sin^{k-1}t ~\cos^{1-k}t ~dt=\frac{1}{2} \frac{\Gamma(k/2)\Gamma(1-k/2)}{\Gamma(1)}= \frac{\pi}{2}\csc(\pi k/2), 0<k<2$$
See for $\beta$ function:  https://en.wikipedia.org/wiki/Beta_function
A: I will use $a$ instead of $\lambda$, it is simpler to type. Since $a-1$ may take negative values, we may have some problems in $0$, so the contour from the OP avoiding $0$ is needed. The following is valid for
$$
a\ne 1\ .
$$
(For this particular value use an other argument or a posteriori the continuity in $a$.)
Let us denote the two contour pieces $C_1$ and $C_2$ from the OP by $C_1(\epsilon,R)$ and $C_2(\epsilon,R)$, also involving $\epsilon$ and $R$.
The expression $x^a$ is then rather defined as $\exp(a \log x)$ with a branch $\log$ for the logarithm defined to coincide with the real natural logarithm $\ln$ on $(0,\infty)$. So we have for $x>0$ the relation
$$(-x)^{a-1}=(-1)^{a-1}\cdot x^{a-1}=\exp(i\pi\; (a-1))\cdot x^{a-1}\ .$$
So let us compute the integral
$$
\begin{aligned}
J(a) 
&:= 
\int_0^{\infty}
\dfrac{x^{a -1}}{x^2+1} \;dx
\\
&=\lim_{\substack{0<\epsilon<R\\\epsilon \to0\\R\to\infty}}
\int_\epsilon^\infty
\dfrac{x^{a -1}}{x^2+1} \;dx
=\lim_{\substack{0<\epsilon<R\\\epsilon \to0\\R\to\infty}}
\int_{C_2(\epsilon,R)}
\dfrac{x^{a -1}}{x^2+1} \;dx\ .
\\[3mm]
&\qquad\text{We have:}
\\[3mm]
\int_{-\infty}^0
\dfrac{x^{a -1}}{x^2+1} \;dx
&
=\int_0^{\infty}
\dfrac{(-x)^{a -1}}{x^2+1} \;dx
=e^{i\pi \; a}\cdot
\int_0^{\infty}
\dfrac{(-x)^{a -1}}{x^2+1} \;dx
\\
&=
e^{i\pi\; a}J(a)\ .
\\[3mm]
\left|\int_{C(\epsilon)}
\dfrac{x^{a -1}}{x^2+1} \;dx
\right|
&\le
\int_{C(\epsilon)}
\dfrac{|x|^{a -1}}{|x^2+1|} \;dx
\le
\int_{C(\epsilon)}
\dfrac{\epsilon^{a -1}}{1-\epsilon^2} \;dx
=\pi\epsilon\cdot\dfrac{\epsilon^{a -1}}{1-\epsilon^2} 
\\
&\to 0\qquad\text{ because $a>0$.}
\\[3mm]
\left|\int_{C(R)}
\dfrac{x^{a -1}}{x^2+1} \;dx
\right|
&\le
\int_{C(R)}
\dfrac{|x|^{a -1}}{|x^2+1|} \;dx
\le
\int_{C(\epsilon)}
\dfrac{R^{a -1}}{R^2-1} \;dx
=\pi R\cdot\dfrac{R^{a -1}}{R^2-1} 
\\
&\to 0\qquad\text{ because $a<2$.}
\\[3mm]
&\qquad\text{This gives:}
\\[3mm]
(1+e^{i\pi\; (a-1)})\cdot J(a)
&=
\lim_{\substack{0<\epsilon<R\\\epsilon \to0\\R\to\infty}}
\int_{C_1(\epsilon,R)\ \sqcup\ C_2(\epsilon,R)}
\dfrac{x^{a -1}}{x^2+1} \;dx
\\
&=
\lim_{\substack{0<\epsilon<R\\\epsilon \to0\\R\to\infty}}
\int_{C_1(\epsilon,R)\ \sqcup \ C(\epsilon)\ \sqcup \ C_2(\epsilon,R)\ \sqcup \ C(R)}
\dfrac{x^{a -1}}{x^2+1} \;dx
\\
&=2\pi\cdot i\sum_{r\text{ Residue}}\operatorname{Res}_{x=r}\dfrac{x^{a -1}}{x^2+1}
\\
&=2\pi\cdot i\cdot \operatorname{Res}_{x=i}\dfrac{x^{a -1}}{x^2+1}
\\
&=2\pi\cdot i\cdot \operatorname{Res}_{x=i}\frac 1{2i}x^{a -1}
\left(\frac 1{x-i}-\frac 1{x+i}\right)
\\
&=2\pi\cdot i\cdot \operatorname{Res}_{x=i}\frac 1{2i}x^{a -1}\cdot \frac 1{x-i}
\\
&=\pi\cdot i^{a-1}=\pi\cdot e^{i\frac \pi 2(a-1)}\ .
\end{aligned}
$$
Now $1+e^{ib}=(1+\cos b)+i\sin b=2\cos ^2\frac b2+2i\sin\frac b2\cos \frac b2=2\cos\frac b2\cdot e^{ib/2}$.
This gives finally:
$$
J(a)
=
\frac
{\pi\cdot \color{blue}{e^{i\frac \pi 2(a-1)}}}
{2\cos\frac \pi 2(a-1)\cdot \color{blue}{e^{i\frac \pi 2(a-1)}}}
=
\frac
\pi
{2\cos\frac \pi 2(1-a)}
=
\frac
\pi
{2\sin\frac {\pi a} 2}
\ .
$$
$\square$
