Comments (4)
I think I figured it out. My browser is set to never give a referal header (because privacy). So, this server was trying to convert an empty string into binary, which doesn't work.
To work around this issue, I changed line 82 (in simple-http-server.py) to:
f.write((b"<br><a href=\".\">Back</a>").encode('utf-8'))
And that seems to have worked! When you have a hyperlink that points to .
, that's a quick and easy way to reload the current page, without needing any POST data. It's basically a relative path to "wherever you already are". The above code also ignores your referal header, so it's not an issue anymore.
Tested with python versions 2.7.18 and 3.8.10
from simple_http_server.
add PR
from simple_http_server.
I will make a PR. But first, I'd like to point out that my above code doesn't seem to work on Python3. I guess *.encode commands don't work well with string that start with an unquoted b
. Here are two pieces of code that seem to work better:
Option 1:
f.write(b"<br><a href=\".\">Back</a>")
Option 2:
f.write(("<br><a href=\".\">Back</a>").encode('utf-8'))
I have no idea which is better. If someone who knows more about Python than I do could weigh in, that'd be great. Maybe it makes no difference?
from simple_http_server.
Since no one has weighed in, I've decided to make a PR with the shorter one. That seems to work well enough. If you choose to accept the PR, feel free to close this report.
from simple_http_server.
Related Issues (10)
- 请问这个支持大文件吗 HOT 3
- AttributeError: module 'signal' has no attribute 'SIGHUP' HOT 1
- Suggestion: Implement "--bind" like python stdlib http.server HOT 5
- 建议将103行的str(line)改为line.decode('utf-8'),并将ascii全局替换成utf-8 HOT 1
- can not upload file HOT 2
- can it support batch upload?
- you can add this into pypi HOT 1
- line 57 SyntaxError HOT 5
- Trying to get in touch with you regarding a security issue HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple_http_server.