Pulling current post/page data into header.php

Main query is actually processed before template is loaded, so data is available in header (if a little less convenient to use).

You don’t actually need loop, get_the_ID() should give you ID for the queried object and most template tags have version that will return you results for that specific ID.

Loop would work just as well, but it’s not very common to run it this early.