Use residues to evaluate $\int_0^\infty \frac{\cosh(ax)}{\cosh(x)}\,\mathrm{d}x$, where $|a|<1$

This doesn't use residues until we use $$ \sum_{k\in\mathbb{Z}}\frac{(-1)^k}{z+k}=\pi\csc(\pi z) $$ which can be proven using residues.

We just expand things in powers of $e^x$: $$ \begin{align} &\int_0^\infty\frac{\cosh(ax)}{\cosh(x)}\,\mathrm{d}x\\ &=\int_0^\infty e^{(a-1)x}\frac{1+e^{-2ax}}{1+e^{-2x}}\,\mathrm{d}x\\ &=\int_0^\infty\left(e^{(a-1)x}-e^{(a-3)x}+e^{(a-5)x}-\dots\right)\,\mathrm{d}x\\ &+\int_0^\infty\left(e^{(-a-1)x}-e^{(-a-3)x}+e^{(-a-5)x}-\dots\right)\,\mathrm{d}x\\ &=\frac1{1-a}-\frac1{3-a}+\frac1{5-a}-\dots\\ &+\frac1{1+a}-\frac1{3+a}+\frac1{5+a}-\dots\\ &=\frac1{a+1}-\frac1{a+3}+\frac1{a+5}-\dots\\ &-\frac1{a-1}+\frac1{a-3}-\frac1{a-5}-\dots\\ &=\frac12\left(\dots+\frac1{\frac{a+1}2-2}-\frac1{\frac{a+1}2-1}+\frac1{\frac{a+1}2}-\frac1{\frac{a+1}2+1}+\frac1{\frac{a+1}2+2}-\dots\right)\\ &=\frac12\pi\csc\left(\pi\frac{a+1}2\right)\\ &=\frac\pi2\sec\left(\frac\pi2a\right) \end{align} $$


Denoting the desired integral by $$I=\int_0^{\infty}\!\!\mathrm{d}x\,\frac{\cosh(ax)}{\cosh x},$$ we may extend the integral to $-\infty<x<\infty$, since the integrand is a symmetric function, i.e. $$\begin{align*}I&=\frac{1}{2}\int_{-\infty}^{\infty}\!\!\mathrm{d}x\,\frac{\cosh(ax)}{\cosh x}\\&=\frac{1}{4}\int_{-\infty}^{\infty}\!\!\mathrm{d}x\,\left(e^{ax}+e^{-ax}\right)\,\mathrm{sech}\,x\\&=\frac{f(a)+f(-a)}{4},\qquad(A)\end{align*}$$ where we have defined $$\displaystyle f(z):=\int_{-\infty}^{\infty}\!\!\mathrm{d}x\,e^{zx}\,\mathrm{sech}\,x.$$ Note, as $x\to\infty$, the hyperbolic secant behaves as $e^{-x}$, hence the integrand $\sim e^{-(1-z)x}$. The integral converges iff $z<1$. Likewise, as $x\to-\infty$, the integrand goes like $e^{(z+1)x}$, hence convergence of the integral requires $z>-1$. Thus $f(z)$ is well-defined for all $|z|<1$, which is also the permitted range for the parameter $a$. That said, let’s return to the evaluation of $f(z)$. $$f(z)=2\int_{-\infty}^{\infty}\!\!\mathrm{d}x\,\frac{e^{zx}}{e^x+e^{-x}}=2\int_{-\infty}^{\infty}\!\!\mathrm{d}x\,\frac{e^{(z-1)x}}{1+e^{-2x}}.$$ Substituting $$\displaystyle 1+e^{-2x}=\frac{1}{u}\Rightarrow\mathrm{d}x=\frac{\mathrm{d}u}{2u^2}e^{2x}=\frac{\mathrm{d}u}{2u(1-u)},$$ and changing the limits of integration appropriately, we arrive at $$\begin{align*}f(z)&=\int_0^1\!\!\mathrm{d}u\,\frac{u^{\frac{z-1}{2}}}{(1-u)^{\frac{z+1}{2}}}\\&=\int_0^1\!\!\mathrm{d}u~u^{\frac{1+z}{2}-1}(1-u)^{\frac{1-z}{2}-1}\\&=\mathrm{B}\!\left(\frac{1+z}{2},\frac{1-z}{2}\right),\end{align*}$$ where $\mathrm{B}(x,y)$ is the beta function (https://en.wikipedia.org/wiki/Beta_function). Expressing the beta function in terms of the gamma function (https://en.wikipedia.org/wiki/Gamma_function), via $$\mathrm{B}(x,y)=\frac{\Gamma(x)\Gamma(y)}{\Gamma(x+y)},$$ and noting that $\Gamma(1)=1$, we can further simplify our result: $$\begin{align*}f(z)&=\Gamma\left(\frac{1+z}{2}\right)\Gamma\left(\frac{1-z}{2}\right)\\&=\Gamma\left(\frac{1+z}{2}\right)\Gamma\left(1-\frac{1+z}{2}\right)\\&=\frac{\pi}{\sin\left(\frac{\pi}{2}+\frac{\pi z}{2}\right)}=\frac{\pi}{\cos\left(\frac{\pi z}{2}\right)}.\end{align*}$$ In the third step above we used Euler’s well know reflection formula (https://en.wikipedia.org/wiki/Reflection_formula) $$\Gamma(x)\Gamma(1-x)=\frac{\pi}{\sin(\pi x)}.$$ Having evaluated $f(z)$ in closed form, we are merely a substitution away from the desired result (cf Eq. (A)). Thus, $$\boxed{\int_0^{\infty}\!\!\mathrm{d}x\,\frac{\cosh(ax)}{\cosh x}=\frac{\pi}{2\cos\left(\frac{\pi a}{2}\right)}}$$

Cheers!