All perfect praise be to Allaah, the Lord of the worlds. I testify that there is none worthy of worship except Allaah and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
First of all, we ask Allaah Almighty to grant you a speedy recovery.
It is well established that if sickness is not chronic, one may break his fast during sickness and then has to make up the days that he did not fast after recovery. Allaah Almighty says (what means): {So whoever among you is ill or on a journey [during them]—then an equal number of days [are to be made up].} [Quran 2: 184]
However, if the sickness is chronic and incurable, then one must break his fast and give food to one poor person for each day that he misses for he is like the one who is unable to fast due to old age. Allaah Almighty says (what means): {And upon those who are able [to fast, but with hardship]—a ransom [as substitute] of feeding a poor person [each day].} [Quran 2: 184]
Ibn ‘Abbas said: “This was a concession granted to the old man and woman who are not able to fast. They are required to feed one poor person for each day.” [Al-Bukhari]
Accordingly, if you cannot fast due to headaches that you suffer from except with great difficulty or that fasting makes it worse and you are told by trustworthy doctors that it is chronic and incurable, then you have to break your fast and give food to one poor person for each day that you miss.
Allaah Knows best.