Maybe replace 
```
  if (done_called_ && last_buf_sent_) {
    // OK means HandleDone has been called
    assert(0);
    *link_ptr = NULL;
    return NGX_OK;
  }
```

with something like this?:
```
CHECK(!(done_called_ && last_buf_sent_)) << "CopyBufferToNginx() was called after the last buffer was sent";
```