Skip to content

Commit

Permalink
Add clarity on how HttpParser class works (#1466)
Browse files Browse the repository at this point in the history
* Add clarity on how `HttpParser` class works

* `"python.analysis.autoImportCompletions": true`
  • Loading branch information
abhinavsingh authored Aug 27, 2024
1 parent 05ac288 commit a51ddaa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
18 changes: 1 addition & 17 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
38 changes: 35 additions & 3 deletions tutorial/http_parser.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
]
},
{
Expand All @@ -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",
Expand All @@ -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`"
]
},
Expand Down Expand Up @@ -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"
]
Expand Down

0 comments on commit a51ddaa

Please sign in to comment.