'Return HTTP bytes representing this request.
If skip_body is True, exclude the body.
If skip_body is an integer larger than one, skip body
only if its length is bigger than that number.'

def as_bytes(self, skip_body=False):

    url = self.url
    host = self.host_url
    assert url.startswith(host)
    url = url[len(host):]
    parts = [bytes_(('%s    %s    %s' % (self.method, url, self.http_version)))]
    body = None
    if (self.method in ('PUT', 'POST')):
        if (skip_body > 1):
            if (len(self.body) > skip_body):
                body = bytes_(('<body    skipped    (len=%s)>' % len(self.body)))
            else:
                skip_body = False
        if (not skip_body):
            body = self.body
    for (k, v) in sorted(self.headers.items()):
        header = bytes_(('%s:    %s' % (k, v)))
        parts.append(header)
    if body:
        parts.extend(['', body])
    return '\r\n'.join(parts)
