For international layover flights, you will normally have to go through customs and immigration at the connecting airport. For flights with a layover in Canada or the USA, you will need to go through immigration and fill out the necessary customs paperwork even if you are not staying in the country.