Perhaps more compactly written:

```
if (from == null) {
    from = Stapler.getCurrentRequest().getHeader("Referer");
    if (from == null) {
        from = Jenkins.getInstance().getRootUrl();
    }
}
```