Giter Club home page Giter Club logo

Comments (4)

tsjnachos117 avatar tsjnachos117 commented on July 17, 2024

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.

freelamb avatar freelamb commented on July 17, 2024

add PR

from simple_http_server.

tsjnachos117 avatar tsjnachos117 commented on July 17, 2024

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.

tsjnachos117 avatar tsjnachos117 commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.