Evaluate $\int \frac{1}{\sin x+\sec x}\,dx $ Evaluate $$\int \frac{1}{\sin x+\sec x}\,dx $$
Expressing $\sin x$ and $\cos x$ in terms of $\tan\frac{x}{2}$ i.e. putting $\sin x=\dfrac{2t}{1+t^2}$, $\cos x=\dfrac{1-t^2}{1+t^2}$ and hence $dx=\dfrac{2\,dt}{1+t^2}$
$$\int \frac{1-t^2}{1+t-t^3}\,dt $$
 A: $$\large{\color\red{\int \frac{\text{d}x}{\sin x+\sec x}}}$$
Substitute $x=\operatorname{gd} u$ and $\text{d}x=\text{sech}\space u$
That leaves us with
$$\int \frac{\operatorname{sech} u\space \text{d}u}{\tanh u+\cosh u}$$
Which can simplify to $$\int \frac{\text{d}u}{\sinh u + \cosh^2 u}$$
To eventually gain your result, allow $a=\sinh u$ This shifts the integral to...
$$\large\color\red{\int{\frac{\text{du}}{a^2+a+1}}}$$
Having a polynomial like this can allow for some slick contour integration, which I will leave up to you.
A: Probably a cleaner expression:
$$I=\int\dfrac{\cos x}{\sin x\cos x+1}dx =\int\dfrac{2\cos x}{2+2\sin x\cos x}dx$$
Now write $2\cos x=\cos x+\sin x+(\cos x-\sin x),$
As $\int(\cos x\pm\sin x)dx=\sin x\mp\cos x$ 
and $(\sin x\mp\cos x)^2=1\mp2\sin x\cos x,$
$$I=\int\dfrac{(\cos x+\sin x)}{3-(\sin x-\cos x)^2}dx+\int\dfrac{(\cos x-\sin x)}{1+(\sin x+\cos x)^2}dx$$
A: $$
\int \frac{1-t^2}{t-t^3} dt = \int \frac{1-t^2}{(1-t^2)t} dt = \int \frac{dt}{t}
 = \ln |t| + C = \ln |\tan(x/2) | +C
$$
as you proved
