GithubHelp home page GithubHelp logo

simplehttpserver's Introduction

Simple Web Server

This is a multi-threaded file-based web server with thread-pooling implemented in Java, with the HTTP/1.1 keep-alive behavior implemented.

The webserver is a static file system that can allow client to have access to the static html files on the server.

Project structure

.
├── WebContent                          # Web root directory containing files for test
|   ├── test.html                              
│   └── index.html              
├── src                                 # Source files
│   ├── main             
|   |   ├── java
|   |   |   └── com.webserve 
|   |   |       ├── config             
|   |   |       |   ├── Configuration             
|   |   |       |   └── ConfigurationManager              
|   |   |       ├── core              
|   |   |       |   ├── ClientHandler              
|   |   |       |   └── WebServer              
|   |   |       ├── exceptions              
|   |   |       |   ├── HttpConfigurationException              
|   |   |       |   ├── HttpExecutionException              
|   |   |       |   └── HttpParsingException             
|   |   |       └── http              
|   |   |           ├── HttpMethod             
|   |   |           ├── HttpParser              
|   |   |           ├── HttpRequest             
|   |   |           ├── HttpResponse             
|   |   |           └── HttpStatusCode             
|   |   └── resources           
|   |       └── log4j2.properties              
│   └── test
|       └── com.webserver.http
|           └── HttpParserTest
├── webserver.properties            # Webserver configuration file
├── pom.xml                         # Maven configuration file
└── README.md

Usage

maven package
java -jar WebServer-1.0-SNAPSHOT.jar [--conf] [Webserver.properties]
# The default configuration file is Webserver.properties

Functions

Configuration

# Webserver.properties
port=8080            # The port of the server.
max_thread_num=100   # The maximum thread number of the thread pool to handle the clients.
webroot=WebContent   # Directory where the files that clients can request are stored.
timeout=5            # The time in seconds that the host will allow an idle connection to remain open before it is closed.

Request methods

According to RFC-2616, the methods GET and HEAD MUST be supported by all general-purpose servers and all other methods are OPTIONAL. This project currently only supports GET and HEAD.

Http request format

     HTTP-message   = method SP request-target SP HTTP-version CRLF
                      *( header-field CRLF )
                      CRLF
                      [ message-body ]

The request-target part specifies the path of the file to access.

The query part (?[key1]=[value1]&[key2]=[value2]) in request-target and message-body are supported but the parsed results are simply ignored.

Example request

GET /index.html HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Cache-Control: max-age=0
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="98", "Google Chrome";v="98"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
cp-extension-installed: Yes
Sec-Fetch-Site: cross-site
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9

Example response

HTTP/1.1 200 OK
Keep-Alive:timeout=5
Connection:keep-alive
Content-Length:143
Content-Type:text/html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>index</title>
</head>
<body>
hello world
</body>
</html>

Status codes

SC_OK(200, "OK"),
SC_BAD_REQUEST(400, "Bad Request"),
SC_METHOD_NOT_ALLOWED(401, "Method Not Allowed"),
SC_NOT_FOUND(404, "Not Found"),

SC_INTERNAL_SERVER_ERROE(500, "Internal Server Error"),
SC_NOT_IMPLEMENTED(501, "Not Implemented");

Keep-alive behavior

If the client specifies Connection: keep-alive in the request message,

  • If the request is processed successfully (status code 200), the connection will be kept alive for another timeout (specified in the configuration file) seconds.
  • If the request is processed unsuccessfully, the connection will be closed.
  • If the connection is idle for more than timeout seconds, the connection will be closed.

If the keep-alive behavior is triggered, the response message will contain Keep-Alive:timeout=[timeout] Connection:keep-alive.

simplehttpserver's People

Contributors

mzp0514 avatar

Watchers

 avatar

simplehttpserver's Issues

同学,您这个项目引入了4个开源组件,存在3个漏洞,辛苦升级一下

检测到 mzp0514/SimpleHttpServer 一共引入了4个开源组件,存在3个漏洞

漏洞标题:Apache Log4j2 < 2.15.0远程代码执行漏洞
缺陷组件:org.apache.logging.log4j:[email protected]
漏洞编号:CVE-2021-44228
漏洞描述:Apache log4j是java中常用的日志记录组件,攻击者发现在小于2.15.0的版本中存在远程代码执行漏洞。
漏洞原因:
由于log4j2默认支持JNDI在内的Lookup查找机制,当日志内容中包含${foo.bar}样式的内容时,会查找相应的值进行替换。因此当用户请求中的内容通过log4j作为日志内容记录时,攻击者可能通过恶意构造的内容,触发log4j的lookup方法,进而执行恶意代码。

影响范围:[2.4, 2.12.3)
最小修复版本:2.12.3
缺陷组件引入路径:org.example:[email protected]>org.apache.logging.log4j:[email protected]

另外还有3个漏洞,详细报告:https://mofeisec.com/jr?p=a1603e

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.