Skip to content

Commit 59dbf10

Browse files
committed
init
1 parent 4b32d55 commit 59dbf10

File tree

21 files changed

+1965
-20
lines changed

21 files changed

+1965
-20
lines changed

.gitignore

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
# Compiled class file
2-
*.class
1+
# Virtual machine crash logs
2+
hs_err_pid*
33

4-
# Log file
5-
*.log
4+
# Gradle build files
5+
.gradle/
66

7-
# BlueJ files
8-
*.ctxt
7+
# IDEA files
8+
.idea/
99

10-
# Mobile Tools for Java (J2ME)
11-
.mtj.tmp/
10+
# Vertx
11+
.vertx
1212

13-
# Package Files #
14-
*.jar
15-
*.war
16-
*.nar
17-
*.ear
18-
*.zip
19-
*.tar.gz
20-
*.rar
13+
# Build
14+
build/
2115

22-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23-
hs_err_pid*
16+
# Log
17+
log/
18+
19+
# Config
20+
config/

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: java
2+
3+
os:
4+
- linux
5+
6+
jdk:
7+
- openjdk8
8+
9+
sudo: false
10+
11+
script: gradle test

README.md

Lines changed: 178 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,178 @@
1-
# zeroproxy
2-
Multi purpose http proxy server
1+
# ZeroProxy is a multi purpose http proxy.
2+
* Support http(https) proxy
3+
* Support websocket proxy (Not yet)
4+
* Support multiple targets
5+
6+
7+
# Supported protocol
8+
* http / https
9+
* ws / wss (Not yet)
10+
11+
12+
# Configuration
13+
14+
## app_config.yml
15+
It's application configuration file.
16+
```yaml
17+
# Server port
18+
port:
19+
main_http: 55550
20+
main_ws: 55551
21+
api_http: 55552
22+
```
23+
24+
## proxy_config.yml
25+
It's proxy configuration file.
26+
```yaml
27+
# Example-1
28+
- location: /zeroproxy_example
29+
type: round-robin
30+
connect_timeout: 3000
31+
idle_timeout: 3000
32+
targets:
33+
- http://1.1.1.1:3000
34+
35+
# Example-2
36+
- location: /zeroproxy/example
37+
type: random
38+
connect_timeout: 3000
39+
idle_timeout: 3000
40+
targets:
41+
- http://1.1.1.1:3000
42+
- http://1.1.1.1:3001
43+
44+
# Example-3
45+
- location: /zeroproxy/example/1
46+
type: all
47+
connect_timeout: 3000
48+
idle_timeout: 3000
49+
targets:
50+
- http://1.1.1.1:3000
51+
- http://1.1.1.1:3001
52+
- http://1.1.1.1:3002
53+
54+
# Example-4
55+
- location: /
56+
type: round-robin
57+
connect_timeout: 3000
58+
idle_timeout: 3000
59+
targets:
60+
- http://1.1.1.1:3000
61+
```
62+
63+
## logback.xml
64+
It's Logback configuration file that is famous logging library.
65+
* You can send error log to Telegram.
66+
1. Uncomment *Telegram* configuration.
67+
2. Set value of `<botToken>` and `<chatId>`.
68+
```xml
69+
<appender name="TELEGRAM" class="com.github.paolodenti.telegram.logback.TelegramAppender">
70+
<botToken></botToken>
71+
<chatId></chatId>
72+
...
73+
</appender>
74+
```
75+
3. Insert `<appender-ref ref="TELEGRAM"/>` into `<root>`
76+
```xml
77+
<root level="WARN">
78+
<appender-ref ref="FILE"/>
79+
<appender-ref ref="TELEGRAM"/>
80+
</root>
81+
```
82+
* You can send error log to Slack.
83+
1. Uncomment *Slack* configuration.
84+
2. Set value of `<webhookUri>`.
85+
```xml
86+
<appender name="SLACK_SYNC" class="com.github.maricn.logback.SlackAppender">
87+
<webhookUri></webhookUri>
88+
...
89+
</appender>
90+
```
91+
3. Insert `<appender-ref ref="SLACK"/>` into `<root>`
92+
```xml
93+
<root level="WARN">
94+
<appender-ref ref="FILE"/>
95+
<appender-ref ref="SLACK"/>
96+
</root>
97+
```
98+
* You can reload configuration but need not to restart application.
99+
100+
101+
# Server
102+
ZeroProxy has three servers.
103+
One is a http proxy server, another is a websocket proxy server, and the other is a restful API server.
104+
Restful API server provide application information and additional functions.
105+
106+
## Main HTTP Server
107+
### Usage
108+
```html
109+
http://example.com:{port}/{location}/{path}
110+
ws://example.com:{port}/{location}/{path}
111+
```
112+
* port
113+
* Server port
114+
* It's *main_http* and *main_ws* in app_config.yml.
115+
* location
116+
* Location
117+
* It's *location* in proxy_config.yml
118+
* path
119+
* Target path
120+
121+
### Example
122+
```html
123+
http://example.com:55550/zeroproxy/example/test.png
124+
```
125+
126+
## API HTTP Server
127+
### Usage
128+
```html
129+
http://example.com:{port}/{domain}/{method}
130+
```
131+
132+
### Example
133+
```html
134+
http://example.com:57911/app/status
135+
http://example.com:57911/app/hello
136+
http://example.com:57911/app/ping
137+
```
138+
139+
### API
140+
#### GET /app/status
141+
* Get application status and environment.
142+
##### Response
143+
```json
144+
{
145+
"data":{
146+
"applicationVersion":"0.1.0-alpha.1",
147+
"cpuUsage":2.56,
148+
"threadInfo":{...},
149+
"vmMemoryFree":"190M",
150+
"javaVersion":"1.8.0_25",
151+
"vmMemoryMax":"3,641M",
152+
"currentDate":"2018-09-18T18:48:58.795+09:00",
153+
"threadCount":15,
154+
"startedDate":"2018-09-18T18:48:40.901+09:00",
155+
"javaVendor":"",
156+
"runningTimeHour":0,
157+
"osName":"Mac OS X",
158+
"cpuProcessorCount":4,
159+
"vmMemoryTotalFree":"3,585M",
160+
"hostname":"",
161+
"osVersion":"10.11.6",
162+
"jarFile":"code13k-zeroproxy-0.1.0-alpha.1.jar",
163+
"vmMemoryAllocated":"245M",
164+
}
165+
}
166+
```
167+
#### GET /app/hello
168+
* Hello, World
169+
##### Response
170+
```json
171+
{"data":"world"}
172+
```
173+
174+
#### GET /app/ping
175+
* Ping-Pong
176+
##### Response
177+
```json
178+
{"data":"pong"}

build.gradle

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
plugins {
2+
id 'java'
3+
id 'application'
4+
}
5+
6+
/**
7+
* Project
8+
*/
9+
group 'org.code13k'
10+
version '0.1.0-alpha.1'
11+
repositories {
12+
jcenter()
13+
}
14+
dependencies {
15+
testCompile group: 'junit', name: 'junit', version: '4.12'
16+
17+
// Log
18+
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
19+
compile group: 'ch.qos.logback', name: 'logback-core', version: '1.2.3'
20+
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
21+
compile group: 'ch.qos.logback', name: 'logback-access', version: '1.2.3'
22+
23+
// Log for telegram
24+
compile group: 'com.github.paolodenti', name: 'telegram-logback', version: '1.2.0'
25+
26+
// Log for slack
27+
compile group: 'com.github.maricn', name: 'logback-slack-appender', version: '1.4.0'
28+
29+
// Java Compiler (For Logback)
30+
compile group: 'org.codehaus.janino', name: 'janino', version: '3.0.8'
31+
32+
// SnakeYAML (YAML Library)
33+
compile group: 'org.yaml', name: 'snakeyaml', version: '1.21'
34+
35+
// Gson (Json Library)
36+
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
37+
38+
// Vert.x (Http Library)
39+
compile group: 'io.vertx', name: 'vertx-core', version: '3.5.3'
40+
compile group: 'io.vertx', name: 'vertx-web', version: '3.5.3'
41+
compile group: 'io.vertx', name: 'vertx-web-client', version: '3.5.3'
42+
compile group: 'io.vertx', name: 'vertx-codegen', version: '3.5.3'
43+
44+
// Util
45+
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
46+
compile group: 'commons-io', name: 'commons-io', version: '2.6'
47+
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
48+
compile group: 'com.google.guava', name: 'guava', version: '26.0-jre'
49+
}
50+
51+
/**
52+
* Java Plugin
53+
*/
54+
sourceCompatibility = 1.8
55+
targetCompatibility = 1.8
56+
jar {
57+
baseName = 'code13k-zeroproxy'
58+
manifest {
59+
attributes(
60+
'Implementation-Title': 'Code13k ZeroProxy',
61+
'Implementation-Version': version,
62+
'Main-Class': 'org.code13k.zeroproxy.Main'
63+
)
64+
}
65+
from {
66+
configurations.runtime.collect {
67+
it.isDirectory() ? it : zipTree(it)
68+
}
69+
configurations.compile.collect {
70+
it.isDirectory() ? it : zipTree(it)
71+
}
72+
}
73+
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
74+
}
75+
compileJava {
76+
options.encoding = 'UTF-8'
77+
options.compilerArgs << "-Xlint:deprecation"
78+
}
79+
compileTestJava {
80+
options.encoding = 'UTF-8'
81+
options.compilerArgs << "-Xlint:deprecation"
82+
}
83+
84+
/**
85+
* Application Plugin
86+
*/
87+
mainClassName = 'org.code13k.zeroproxy.Main'
88+
89+
/**
90+
* Custom
91+
*/
92+
task runJar(dependsOn: jar) {
93+
doLast {
94+
javaexec {
95+
main = "-jar"
96+
args = [jar.archivePath]
97+
}
98+
}
99+
}

gradle/wrapper/gradle-wrapper.jar

53.1 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Tue Sep 18 00:39:54 KST 2018
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip

0 commit comments

Comments
 (0)