Over the past few days, I started putting together some notes for an article about an upcoming WebAssembly feature in the Firefox browser. The trick with the feature is that, to enable it, the webserver needs to return certain headers.
Because the article I’m going to write will be a continuation of a topic from my book, “WebAssembly in Action”, I thought it would be best to continue to use Python as the local webserver.
As it turns out, running Python’s web server from the command line doesn’t give an option to include response headers. Fortunately, it’s not hard to extend the webserver which you’ll learn how to do in this article.
As a bonus, there’s another advantage of extending Python’s local web server. WebAssembly files (.wasm) need to be served with the ‘application/wasm’
Media Type but Python didn’t have that value specified in versions older than 3.7.5. By extending the web server, you can include the Media Type without needing to modify any of Python’s files which simplifies getting up and running with WebAssembly.
The Python code that you’ll need to write is slightly different between the 2.x and 3.x versions of Python so the first thing you need to do is determine which version you have on your machine.
Python’s Version
To check which version of Python you have installed, open a console window, and run the following command: python --version
You should see the version displayed similar to the following image:
Over the past few days, I started putting together some notes for an article about an upcoming WebAssembly feature in the Firefox browser. The trick with the feature is that, to enable it, the webserver needs to return certain headers.Because the article I’m going to write will be a continuation of a topic from my book, “WebAssembly in Action”, I thought it would be best to continue to use Python as the local webserver.As it turns out, running Python’s web server from the command line doesn’t give an option to include response headers. Fortunately, it’s not hard to extend the webserver which you’ll learn how to do in this article.As a bonus, there’s another advantage of extending Python’s local web server. WebAssembly files (.wasm) need to be served with the ‘application/wasm’ Media Type but Python didn’t have that value specified in versions older than 3.7.5. By extending the web server, you can include the Media Type without needing to modify any of Python’s files which simplifies getting up and running with WebAssembly.The Python code that you’ll need to write is slightly different between the 2.x and 3.x versions of Python so the first thing you need to do is determine which version you have on your machine.
Python’s Version
To check which version of Python you have installed, open a console window, and run the following command: python –versionYou should see the version displayed similar to the following image: […]