# Why does shifting the integration line from the real-axis not affect the integral $\int_{-\infty}^\infty e^{-x^2} dx$? [duplicate]

I know that $$\int_{-\infty}^\infty e^{-x^2} dx = \sqrt{\pi},$$ and clearly this integral is invariant under translation along the real axis. But today I learned that $$\int_{-\infty}^\infty e^{-(x+ik)^2} dx = \sqrt{\pi}$$ holds for any choice of constant $k \in \mathbb{R}$, so we even have translation invariance along the imaginary axis. Why is that?

More generally, suppose we have $K > 0$ and a function $f(z)$ analytic in the strip $\{z: \text{Im}(z) < K\}$, such that $|f(x+iy)| \to 0$ as $|x| \to \infty$ uniformly in $y \in (-K,K)$, and such that $\int_{-\infty}^\infty f(x)\; dx$ exists in the Cauchy principal value sense, i.e. $\lim_{R \to \infty} \int_{-R}^R f(x)\; dx = J$ exists. Then for any $y \in (-K,K)$, we also have $\int_{-\infty}^\infty f(x+iy)\; dx = J$ in the Cauchy principal value sense.
Proof: consider the rectangular contour with corners at $-R$, $R$, $R + iy$, $-R+iy$, and use the Cauchy integral theorem together with bounds on the contributions of the vertical segments.