<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Http Response
Usage
To construct a response packet you have a variety of facilities available.
Previously we saw how to parse HTTP responses using HttpParser.  Of-course, we can also construct a response packet using HttpParser class.
Step1:  But, this is a painful way to construct responses.  Hence, other high level abstractions are available.
Example, following one liner will give us the same response packet.
Step2:  Notice how okResponse will always add a Content-Length header for you.
You can also customize other headers
Step3:  Let's add some content to our response packet
Step4:  Note, how okResponse automatically added a Content-Length header for us.
Depending upon --min-compression-length flag, okResponse will also perform compression for content.
Example, default value for min compression length is 20.
Step5:  You can pass a custom value for min_compression_length kwarg to okResponse.
Step6:  Internally, okResponse uses build_http_response and hence you can also pass any argument also accepted by build_http_response.  Example, it supports a conn_close argument which will add a Connection
Step7:  Chunked Encoding
You can also send chunked encoded responses.
Step8:  If we omit the min_compression_length flag
<ASSISTANT_TASK:>
Python Code:
from proxy.http.parser import HttpParser, httpParserTypes
from proxy.common.constants import HTTP_1_1
response = HttpParser(httpParserTypes.RESPONSE_PARSER)
response.code = b'200'
response.reason = b'OK'
response.version = HTTP_1_1
print(response.build_response())
Explanation: Http Response
Usage
To construct a response packet you have a variety of facilities available.
Previously we saw how to parse HTTP responses using HttpParser.  Of-course, we can also construct a response packet using HttpParser class.
End of explanation
from proxy.http.responses import okResponse
print(okResponse().tobytes())
Explanation: But, this is a painful way to construct responses.  Hence, other high level abstractions are available.
Example, following one liner will give us the same response packet.
End of explanation
response = okResponse(
    headers={
        b'X-Custom-Header': b'my value',
    },
)
print(response.tobytes())
Explanation: Notice how okResponse will always add a Content-Length header for you.
You can also customize other headers
End of explanation
response = okResponse(
    content=b'Hello World',
    headers={
        b'X-Custom-Header': b'my value',
    },
)
print(response.tobytes())
Explanation: Let's add some content to our response packet
End of explanation
response = okResponse(
    content=b'H' * 21,
    headers={
        b'X-Custom-Header': b'my value',
    },
)
print(response.tobytes())
Explanation: Note, how okResponse automatically added a Content-Length header for us.
Depending upon --min-compression-length flag, okResponse will also perform compression for content.
Example, default value for min compression length is 20.
End of explanation
response = okResponse(
    content=b'H' * 21,
    headers={
        b'Host': b'jaxl.com',
    },
    min_compression_length=21,
)
print(response.tobytes())
Explanation: You can pass a custom value for min_compression_length kwarg to okResponse.
End of explanation
response = okResponse(
    content=b'Hello World',
    headers={
        b'Host': b'jaxl.com',
    },
    conn_close=True,
)
print(response.tobytes())
Explanation: Internally, okResponse uses build_http_response and hence you can also pass any argument also accepted by build_http_response.  Example, it supports a conn_close argument which will add a Connection: close header.  Simply, pass conn_close=True.
End of explanation
from proxy.http.parser import ChunkParser
chunks = ChunkParser.to_chunks(b'Hello World', chunk_size=5)
response = okResponse(
    content=chunks,
    headers={
        b'Transfer-Encoding': b'chunked',
    },
    # Avoid compressing chunks for demo purposes here
    # Ideally you should omit this flag and send
    # compressed chunks.
    min_compression_length=len(chunks),
)
print(response.tobytes())
Explanation: Chunked Encoding
You can also send chunked encoded responses.
End of explanation
response = okResponse(
    content=chunks,
    headers={
        b'Transfer-Encoding': b'chunked',
    },
)
print(response.tobytes())
Explanation: If we omit the min_compression_length flag
End of explanation
<END_TASK>