How Gravity affects Light?

Let's clarify a couple of things first.

1. As you say, light bends by the effect of gravity; That is a fact.
2. Light has no mass; thanks to this it can travel at the speed at which it does.
3. Light travels in a straight line.

So why does it curve?

All right. Isaac Newton, first, suggested that the gravitational attraction between two bodies was proportional to the product of the masses and inversely proportional to the square of the distance between them. Or, simply put; dough attracts dough. Newton gave us the formula to calculate this attraction, and we thank him to this day for it.

However, much later, in the year 1915, a great physicist postulated "Theory of General Relativity". He was Albert Einstein. He suggested that gravity is not an attractive force between two bodies, but rather the deformation of a tissue that he called spacetime.

I'll explain it to you with the classic example: If you have a mesh, and you place a marble in it, the mesh will curve, causing anybody in it to move towards the marble you placed in the first place. Thus, the Sun, for example, warps space-time causing the trajectories of everything around it (such as the Earth) to be affected. How Gravity affects Light?

However, light travels in a straight line ... right? Yes. It does. But the space-time in which it travels is curved (exerting gravity). Thus, it seems that light is bent by the effect of this gravity. Or rather, it does; It curves! It is not a matter of perspective, it is a fact. But in reality, it is traveling in a straight line through the continuous fabric of space-time, which, by the presence of energy (mass of another body), bends.

The End Notes

According to general relativity, which has passed every experimental and observational test to date and is a fantastically accurate theory of gravity, gravity is the bending of spacetime by mass energy. Gravity doesn’t affect light; light travels along straight lines in spacetime. However, mass energy turns those straight lines into curved paths.