Let's work on the integral

The best way to solve this integral is to realize that $1+\cos x=2\cos^2\left(\dfrac{x}{2}\right)$, which would lead immediately to

but in case one does not catch on, an implicit change of variable will be useful again. Suppose we proceed in an explicit way:

And $\dfrac{1}{2}\left(1+\tan^2\left(\dfrac{x}{2}\right)\right)=\dfrac{1}{1+\cos x}$, so we would have indeed

which essentially is the same as above. But: would the integrand be slightly different, the change of variable could not have been applied. Instead, an implicit change of variable $h(t)=x$ is *always* appliable - we'll stress this subtlety later. For now, we take the form

We also need to express $\cos x$ in terms of $t$: if $\tan\left(\dfrac{x}{2}\right)=t$, then (check it!)

and therefore

Smart, isn't it? But it doesn't seem to outperform the explicit change of variable, so we will slightly modify our integrand

Now the integral is not immediate nor the term $\dfrac{1}{2}\left(1+\tan^2\left(\dfrac{x}{2}\right)\right)=\dfrac{1}{1+\cos x}$ appears. But the implicit change of variable is easily applied

Amazing! It's your turn to differentiate and check that everything works fine