<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 Requests
Usage
To construct a HTTP request packet you have a variety of facilities available.
Previously we saw how to parse HTTP responses using HttpParser.  We also saw how HttpParser class is capable of parsing various type of HTTP protocols.  Remember the take away from that tutorial.
Step1:  But, this is a painful way to construct request packets.  Hence, other high level abstractions are available.
Example, following one liner will give us the same request packet.
Step2:  build_http_request ensures a User-Agent header.  You can provide your own too
Step3:  Or, if you don't want a User-Agent header at all
Step4:  To add a connection close header, simply pass conn_close=True
Step5:  For POST requests, provide the body attribute
Step6:  For chunked data, simply include a Transfer-Encoding header.  This will omit the Content-Length header then
<ASSISTANT_TASK:>
Python Code:
from proxy.http.parser import HttpParser, httpParserTypes
from proxy.http import httpMethods
from proxy.common.utils import HTTP_1_1
request = HttpParser(httpParserTypes.REQUEST_PARSER)
request.path, request.method, request.version = b'/', httpMethods.GET, HTTP_1_1
request.add_header(b'Host', b'jaxl.com')
print(request.build())
Explanation: Http Requests
Usage
To construct a HTTP request packet you have a variety of facilities available.
Previously we saw how to parse HTTP responses using HttpParser.  We also saw how HttpParser class is capable of parsing various type of HTTP protocols.  Remember the take away from that tutorial.
End of explanation
from proxy.common.utils import build_http_request
build_http_request(
    method=httpMethods.GET,
    url=b'/',
    headers={b'Host': b'jaxl.com'},
)
Explanation: But, this is a painful way to construct request packets.  Hence, other high level abstractions are available.
Example, following one liner will give us the same request packet.
End of explanation
build_http_request(
    method=httpMethods.GET,
    url=b'/',
    headers={
        b'Host': b'jaxl.com',
        b'User-Agent': b'my app v1'
    },
)
Explanation: build_http_request ensures a User-Agent header.  You can provide your own too:
End of explanation
build_http_request(
    method=httpMethods.GET,
    url=b'/',
    headers={b'Host': b'jaxl.com'},
    no_ua=True,
)
Explanation: Or, if you don't want a User-Agent header at all
End of explanation
build_http_request(
    method=httpMethods.GET,
    url=b'/',
    headers={b'Host': b'jaxl.com'},
    conn_close=True,
)
Explanation: To add a connection close header, simply pass conn_close=True
End of explanation
build_http_request(
    method=httpMethods.POST,
    url=b'/',
    headers={b'Host': b'jaxl.com'},
    body=b'key=value&hello=world',
    content_type=b'application/x-www-form-urlencoded',
    conn_close=True,
)
Explanation: For POST requests, provide the body attribute
End of explanation
from proxy.http.parser import ChunkParser
build_http_request(
    method=httpMethods.POST,
    url=b'/',
    headers={
        b'Host': b'jaxl.com',
        b'Transfer-Encoding': b'chunked',
    },
    body=ChunkParser.to_chunks(b'key=value&hello=world', chunk_size=5),
    content_type=b'application/x-www-form-urlencoded',
    conn_close=True,
)
Explanation: For chunked data, simply include a Transfer-Encoding header.  This will omit the Content-Length header then:
End of explanation
<END_TASK>