Giter Club home page Giter Club logo

simple_http_server's Introduction

simple_http_server

Build Status

Features

  • ✔ simple
  • ✔ upload
  • ✔ download
  • ✔ support python2, python3

Usage

# get code
$ git clone https://github.com/freelamb/simple_http_server.git

# enter directory
$ cd simple_http_server

# run server
$ python simple_http_server.py 8000

# run as docker container
# 1.build the image('.' below refer to the root path of this project)
docker build -t freelamb/simple_http_server .
# 2.run the container using the image built just now in docker 
docker run 
  --name simple_http_server \ 
  -p 8000:8000 \ 
  -v /opt/data:/opt/data \ 
  -d freelamb/simple_http_server:latest

Example

Todo

  • support Multi-threaded
  • add docker images
  • add to pypi

Contributing

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
  2. Fork the repository_ on GitHub to start making your changes to the master branch (or branch off of it).
  3. Write a test which shows that the bug was fixed or that the feature works as expected.
  4. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to AUTHORS_.

Changelog

Changelog

reference

https://github.com/tualatrix/tools/blob/master/SimpleHTTPServerWithUpload.py

License

MIT

simple_http_server's People

Contributors

edisonx-sudo avatar freelamb avatar sharkkkk avatar tsjnachos117 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

simple_http_server's Issues

Trying to get in touch with you regarding a security issue

Hi there,

I couldn't find a SECURITY.md in your repository and so am not sure how to best contact you privately to disclose the security issue.

Can you add a SECURITY.md file with your e-mail to your repository, so that I know who to contact? GitHub suggests that a security policy is the best way to make sure security issues are responsibly disclosed.

Once you've done that, please let me know so I can ping you the info.

Thanks! (cc @JamieSlome)

Crashes after upload

As soon as I download a file, this server crashes. The file uploads just fine, and the program keeps running, so I can upload/download more files, but when I get a "Connection was reset" error in my browser, it's easy to assume the upload failed.

Here's the terminal output with python3:

server_version: simple_http_server/0.3.1, python_version: Python/3.8.10
sys encoding: utf-8
Serving http on: 0.0.0.0, port: 8000 ... (http://0.0.0.0:8000/)
True File '/dev/shm/simple_http_server/test_file' upload success! by:  ('127.0.0.1', 55798)
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 55798)
Traceback (most recent call last):
  File "/usr/lib/python3.8/socketserver.py", line 316, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.8/socketserver.py", line 347, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.8/socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.8/socketserver.py", line 747, in __init__
    self.handle()
  File "/usr/lib/python3.8/http/server.py", line 427, in handle
    self.handle_one_request()
  File "/usr/lib/python3.8/http/server.py", line 415, in handle_one_request
    method()
  File "simple_http_server.py", line 82, in do_POST
    f.write(b"<br><a href=\"%s\">back</a>" % self.headers['referer'].encode('utf-8'))
AttributeError: 'NoneType' object has no attribute 'encode'
----------------------------------------
^CYou chose to stop me.

And Here's the python2 output:

server_version: simple_http_server/0.3.1, python_version: Python/2.7.18
sys encoding: utf-8
Serving http on: 0.0.0.0, port: 8000 ... (http://0.0.0.0:8000/)
(True, u"File '/dev/shm/test_file' upload success!", 'by: ', ('127.0.0.1', 55800))
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 55800)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 293, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 655, in __init__
    self.handle()
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request
    method()
  File "simple_http_server.py", line 82, in do_POST
    f.write(b"<br><a href=\"%s\">back</a>" % self.headers['referer'].encode('utf-8'))
  File "/usr/lib/python2.7/rfc822.py", line 393, in __getitem__
    return self.dict[name.lower()]
KeyError: 'referer'
----------------------------------------
^CYou choose to stop me.

upload succeeded, but an exception occurred

server_version: simple_http_server/0.3.2, python_version: Python/3.11.1
sys encoding: utf-8
Serving http on: 0.0.0.0, port: 8000 ... (http://0.0.0.0:8000/)
192.168.31.64 - - [09/Jun/2024 23:20:03] "GET / HTTP/1.1" 200 -
192.168.31.64 - - [09/Jun/2024 23:20:03] code 404, message File not found
192.168.31.64 - - [09/Jun/2024 23:20:03] "GET /favicon.ico HTTP/1.1" 404 -

Exception occurred during processing of request from ('192.168.31.64', 54148)
Traceback (most recent call last):
File "D:\Python311\Lib\socketserver.py", line 317, in _handle_request_noblock
self.process_request(request, client_address)
File "D:\Python311\Lib\socketserver.py", line 348, in process_request
self.finish_request(request, client_address)
File "D:\Python311\Lib\socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "D:\Python311\Lib\socketserver.py", line 755, in init
self.handle()
File "D:\Python311\Lib\http\server.py", line 432, in handle
self.handle_one_request()
File "D:\Python311\Lib\http\server.py", line 400, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Python311\Lib\socket.py", line 706, in readinto
return self._sock.recv_into(b)
^^^^^^^^^^^^^^^^^^^^^^^
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host.

True File 'C:\Users\QY\Documents\simple_http_server\Screenshot_20240604_202716.jpg' upload success! by: ('192.168.31.64', 54166)

I have confirmed that the file has been uploaded, but got error "can't connect to this network" after clicking "back". BTW my phone chrome browser was used to access the server.

can not upload file

~ $ cd simple_http_server
~/simple_http_server $ python simple_http_server.py 8000
server_version: simple_http_server/0.3.1, python_version: Python/3.11.3
sys encoding: utf-8
Serving http on: 0.0.0.0, port: 8000 ... (http://0.0.0.0:8000/)
10.0.0.149 - - [29/May/2023 11:22:14] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [29/May/2023 11:22:14] "GET / HTTP/1.1" 200 -

Exception occurred during processing of request from ('127.0.0.1', 45442)
Traceback (most recent call last):
File "/data/data/com.termux/files/usr/lib/python3.11/socketserver.py", line 317, in _handle_request_noblock
self.process_request(request, client_address)
File "/data/data/com.termux/files/usr/lib/python3.11/socketserver.py", line 348, in process_request
self.finish_request(request, client_address)
File "/data/data/com.termux/files/usr/lib/python3.11/socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/data/data/com.termux/files/usr/lib/python3.11/socketserver.py", line 755, in init
self.handle()
File "/data/data/com.termux/files/usr/lib/python3.11/http/server.py", line 432, in handle
self.handle_one_request()
File "/data/data/com.termux/files/usr/lib/python3.11/http/server.py", line 420, in handle_one_request
method()
File "/data/data/com.termux/files/home/simple_http_server/simple_http_server.py", line 59, in do_GET
shutil.copyfileobj(fd, self.wfile)
File "/data/data/com.termux/files/usr/lib/python3.11/shutil.py", line 200, in copyfileobj
fdst_write(buf)
File "/data/data/com.termux/files/usr/lib/python3.11/socketserver.py", line 834, in write
self._sock.sendall(b)
BrokenPipeError: [Errno 32] Broken pipe

line 57 SyntaxError

File "simple_http_server.py", line 57
print r, info, "by: ", self.client_address
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(r, info, "by: ", self.client_address)?

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.