It depends on the headlock really but there are many methods of breaking free of headlocks and general close grips.
For the headlock I like the Brazillian JiuJitsu method of picking up the person and slamming them on thier backs. The headlock is quite harmless if you are used to ther discomfort of being choked senseless as most combat grapplers are. When viewed this way they are a great way to drain the opponents batteries of energy. he will squeeze for dear life on your head to no avail if you relax and breath through it. By putting him on the ground you put yourself on top and then once he tires of the headlock attempt you will be in side control. As a general rule when being choked you work yourself towards the open part of the lock or choke to make space to breath and let the blood flow.
For clearing people of close binds or clinches there are a bunch of techniques from the manuals.
Paulus Hector Mair manual teaches a methiod of closing the fists and pressing straight outwards to free yourself from a grip. (David Knight will correct me if I am wrong)
The Joachim Meyer manual has an interesting method of balling up the fists and crossing the arms when bear hugged or clinched, then as you shoot around generously with your elbows you free yourself with great leverage from any bind or clinch.
Ancient Pankration uses methods to escape binds very similar to modern MMA/NBH (not surprisingly)
This one works well against most clinches, working both hands into the bind and being especially mindful of your base which the opponent is going to try and topple as soon as he takes a dominate clinch position like this, base out and press out and you can make space to twist/spin out or simply get into a good sprawl.
and finally Wrestling and BJJ have my favorite method for free yourself from a tight bind/grip/clinch and that is to base out with a sprawl like footwork and push both palms into the face or even under the nose/chin of the opponent to make space and push vigorously.