Add clarity on how `HttpParser` class works (#1466)
* Add clarity on how `HttpParser` class works * `"python.analysis.autoImportCompletions": true`
This commit is contained in:
parent
05ac288620
commit
a51ddaae41
|
@ -21,27 +21,11 @@
|
|||
"editor.wordBasedSuggestions": "matchingDocuments",
|
||||
"editor.defaultFormatter": "ms-python.black-formatter"
|
||||
},
|
||||
"python.analysis.autoImportCompletions": true,
|
||||
"python.testing.unittestEnabled": false,
|
||||
"python.testing.autoTestDiscoverOnSaveEnabled": true,
|
||||
"python.testing.pytestEnabled": true,
|
||||
"python.testing.pytestArgs": ["tests"],
|
||||
"python.linting.enabled": true,
|
||||
"python.linting.lintOnSave": true,
|
||||
"python.linting.ignorePatterns": [
|
||||
".tox/**/*.py",
|
||||
".vscode/*.py",
|
||||
".venv*/**/*.py",
|
||||
"venv*/**/*.py",
|
||||
"docs/**/*.py",
|
||||
"helper/**/*.py"
|
||||
],
|
||||
"python.linting.pylintEnabled": true,
|
||||
"python.linting.pylintArgs": ["--generate-members"],
|
||||
"python.linting.flake8Enabled": true,
|
||||
"python.linting.flake8Args": ["--config", ".flake8"],
|
||||
"python.linting.mypyEnabled": true,
|
||||
"python.formatting.provider": "autopep8",
|
||||
"autoDocstring.docstringFormat": "sphinx",
|
||||
"emeraldwalk.runonsave": {
|
||||
"commands": [
|
||||
{
|
||||
|
|
|
@ -6,9 +6,16 @@
|
|||
"source": [
|
||||
"# HttpParser\n",
|
||||
"\n",
|
||||
"`HttpParser` class is at the heart of everything related to HTTP. It is used by Web server and Proxy server core and their plugin eco-system. As the name suggests, it is capable of parsing both HTTP request and response packets. It can also parse HTTP look-a-like protocols like ICAP, SIP etc. Most importantly, remember that `HttpParser` was originally written to handle HTTP packets arriving in the context of a proxy server and till date its default behavior favors the same flavor.\n",
|
||||
"`HttpParser` class is at the heart of everything related to HTTP. It is used by `Web server` and `Proxy server` core and their plugin eco-system. As the name suggests, it is capable of parsing both HTTP request and response packets. It can also parse HTTP look-a-like protocols like ICAP, SIP etc. Most importantly, remember that `HttpParser` was originally written to handle HTTP packets arriving in the context of a proxy server and till date its default behavior favors the same flavor."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## HTTP Web Requests\n",
|
||||
"\n",
|
||||
"Let's start by parsing a HTTP web request using `HttpParser`"
|
||||
"Let's parse a typical HTTP web request using `HttpParser`"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -32,6 +39,7 @@
|
|||
"get_request = HttpParser(httpParserTypes.REQUEST_PARSER)\n",
|
||||
"get_request.parse(memoryview(b'GET / HTTP/1.1\\r\\nHost: jaxl.com\\r\\n\\r\\n'))\n",
|
||||
"\n",
|
||||
"# Rebuild the raw request\n",
|
||||
"print(get_request.build())\n",
|
||||
"\n",
|
||||
"assert get_request.is_complete\n",
|
||||
|
@ -50,6 +58,19 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"> NOTE:\n",
|
||||
">\n",
|
||||
"> `get_request.host` is `None`\n",
|
||||
"> \n",
|
||||
"> We use `get_request.header(b'host') == b'jaxl.com'` to get the expected host value"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## HTTP Proxy Requests\n",
|
||||
"\n",
|
||||
"Next, let's parse a HTTP proxy request using `HttpParser`"
|
||||
]
|
||||
},
|
||||
|
@ -90,7 +111,18 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Notice how `proxy_request.build()` and `proxy_request.build(for_proxy=True)` behave. Also, notice how `proxy_request.host` field is populated for a HTTP proxy packet but not for the prior HTTP web request packet example.\n",
|
||||
"> NOTE:\n",
|
||||
">\n",
|
||||
"> Notice how `proxy_request.build()` and `proxy_request.build(for_proxy=True)` behave\n",
|
||||
">\n",
|
||||
"> Also, here `proxy_request.host` field is populated\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## HTTPS Proxy Requests\n",
|
||||
"\n",
|
||||
"To conclude, let's parse a HTTPS proxy request"
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue