'Builds HTTPResponse object for streaming.'

def _BuildStreamingResponse(self, binary_stream, method_name=None):

    content = binary_stream.GenerateContent()
    try:
        peek = content.next()
        stream = itertools.chain([peek], content)
    except StopIteration:
        stream = []
    response = werkzeug_wrappers.Response(response=stream, content_type='binary/octet-stream', direct_passthrough=True)
    response.headers['Content-Disposition'] = ('attachment;    filename=%s' % binary_stream.filename)
    if method_name:
        response.headers['X-API-Method'] = method_name
    if binary_stream.content_length:
        response.content_length = binary_stream.content_length
    return response
