Factor out XFF append handling into a common function

Change-Id: I42587b856dfc533bd25358d9bd514d4a1119582a