Old English hæt "hat, head covering" (variously glossing Latin pileus, galerus, mitra, tiara), from Proto-Germanic *hattuz "hood, cowl" (source also of Frisian hat, Old Norse hattr, höttr "a hood or cowl"), of uncertain etymology; it has been compared with Lithuanian kuodas "tuft or crest of a bird" and Latin cassis "helmet" (but this is said to be from Etruscan).
To throw (one's) hat in the ring was originally (1847) to take up a challenge in prize-fighting. To eat one's hat (1770), expressing what one will do if something he considers a sure thing turns out not to be, is said to have been originally eat Old Rowley's [Charles II's] hat.
rack n.1
c. 1300, "grating or open frame with bars or pegs upon which things are hung or placed," especially for kitchen use, possibly from Middle Dutch rec "framework," literally "something stretched out, related to recken (modern rekken) "stretch out," cognate with Old English reccan "to stretch out," from Proto-Germanic *rak- (source also of Old Saxon rekkian, Old Frisian reza, Old Norse rekja, Old High German recchen, German recken, Gothic uf-rakjan "to stretch out"), from PIE root *reg- "to move in a straight line."
Or it might have developed from the Old English verb. The sense of "frame on which clothes or skins are stretched to dry" is by early 14c. The sense of "framework above a manger for holding hay or other fodder for livestock" is from mid-14c. As the name of a type of instrument of torture by early 15c., perhaps from German rackbank, originally an implement for stretching leather, etc. Sense of "punishment by the rack" is by 1580s.
Mechanical meaning "metal bar with teeth on one edge" is from 1797 (see pinion). Meaning "set of antlers" is first attested 1945, American English; hence slang sense of "a woman's breasts" (especially if large), by 1991. Meaning "framework for displaying clothes" is from 1948; hence off the rack (1951) of clothing, as opposed to tailored.