This same code is also used when signing the requests. Could you extract/refactor it so you have it only in one place?