The Gemara in Masechet (tractate) Berachot discusses the beracha (blessing) for drinking olive oil straight up. The Gemara concludes that one does not make a beracha at all on drinking olive oil because it is mazik, because it causes harm to the body. Whether that is true today, or whether the evidence would suggest something different—that a person would make a beracha—is not as relevant as the question of whether a person makes a beracha on food that is harmful to their body.
From this Gemara, it would seem that if a person is going to ingest something that is going to be mazik, that is going to cause their body harm, then the person is not going to make a beracha. However, let’s say a person has a gluten sensitivity, for example, but they really desire to eat bread, and they are going to eat the bread and deal with the consequences that come afterward, right? Or a person has a slight sensitivity to another food, but they really enjoy the taste of the food and really want to eat it, even though they know that afterward it is going to leave them in a somewhat compromised state. A beracha is still recited.
At the end of the day, the person is getting enjoyment from the taste of the food, and their body is receiving some level of nourishment. Even though it will cause them a little bit of harm, which they are willing to endure, or they are willing to take a pill afterward or something like that, a beracha would still be recited.
It is also worth noting that a person only makes a beracha if they ingest food in the normal fashion of eating. This would suggest that if, lo aleinu (God forbid), a person needed to be fed through a tube or through a PEG, even though their body is receiving nourishment and ingesting things that will sustain it, a beracha is not recited because this is not happening in derech achila (normal fashion of eating).

