I know this is an old thread, but I just did some reading on this, and I thought it might be useful info.
On AR barrels, headspace is set when the barrel and barrel extension are made. This is usually done by the gunsmith/manufacturer/barrel maker. In some cases, high end shops will match bolt heads to barrel extensions for an exact fit.
However, AR bolt and carrier groups can be swapped out without worrying about headspace. They were designed to be interchangeable and easy to replace in the field in case of failure. If you have a low-mileage AR, and you want to put a new bolt/carrier group in it, you can do so without worrying about headspace. If you are concerned, a quick check with a go/no-go gauge can tell you if there is a problem.
On the flip side, if you have a high mileage piece, and things are getting sloppy due to bolt lug wear, its highly advisable to do a check with the go/no-go gauges prior to returning to the range.
Unless its a permanent swap, switching bolt/carrier groups from one upper to another is not recommended. Most wear on bolt/carrier groups occurs on the rear of the locking lugs, where they meet the front of the barrel extension locking lugs. if constantly swapped, they will never wear evenly.