I think OpenGL is not using a midpoint interpolation, as it's probably simpler to just draw two triangles to have a line and lines being a rare case, it's probably 'good enough', which is maybe why it's also not that fast to draw lines, while you'd expect it to be simpler than drawing triangles.
you could check MesaGL, a software implementation for the Opengl API to see how they do it, but it might not be what the HW does.
for proper shading, you can
-divide the gradient by the count of steps you gonna take, the count of steps is the metropolitan distance, deltax+deltay, and add it on every step. not fully accurate, but you probably won't notice a difference and it's fast
-baricentrical distance: calculate the the distances at every (x,y) to both ends, weight the colors by those distances, divided by their sum
-if you make a dot product of the (x,y) with the direction vector of the line and divide by the length of the direction vector, no matter what width your line will have (so even if it's wider than long), you'll draw a gradient that always progresses from one end to the other.