The Wayback Machine - https://web.archive.org/web/20230417065518/https://github.com/XTLS/Xray-core/pull/365
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add HTTP Web Server #365

Closed
wants to merge 1 commit into from
Closed

feat: Add HTTP Web Server #365

wants to merge 1 commit into from

Conversation

CerteKim
Copy link

@CerteKim CerteKim commented Mar 12, 2021

Features

  • HTTP Web Server.
  • Provide HTTP APIs mapped to gRPC APIs
  • pprof

Configure

web server configuration:

{
    "web":{
        "tag":"web",
        "api": {
            "address": "127.0.0.1",
            "port": 65534
        },
        "pprof": true,
        "static": [
            {
                "filePath": "/path/to/static/files",
                "uri": "/app"
            },
            {
                "filePath": "/another/to/static/files",
                "uri": "/"
            }
        ]
    }
}

"tag" : Outbound tag
"address" : gRPC server address, default 127.0.0.1
"port" : gRPC server port, default 0 ( When 0, xray won't dial gRPC server )
"pprof" : turn on/off pprof
"static": Serve web static file.

inbound:

{
    "inbounds": [
        {
            "tag": "api",
            "port": 65534,
            "listen": "127.0.0.1",
            "protocol": "dokodemo-door",
            "settings": {
                "udp": false,
                "address": "127.0.0.1",
                "allowTransparent": false
            }
        },
        {
            "tag": "web",
            "port": 80,
            "listen": "127.0.0.1",
            "protocol": "dokodemo-door",
            "settings": {
                "address": "127.0.0.1"
            }
        }
    ]
}

routing:

{
    "routing": {
        "rules": [
            {
                "inboundTag": [
                    "api"
                ],
                "outboundTag": "api",
                "type": "field"
            },
            {
                "type": "field",
                "inboundTag": [
                    "web"
                ],
                "outboundTag": "web"
            }
        ]
    }
}

api related:

{
    "api": {
        "tag": "api",
        "services": [
            "HandlerService",
            "LoggerService",
            "StatsService"
        ]
    },
    "stats":{},
    "policy": {
        "levels": {
            "0": {
                "handshake": 4,
                "connIdle": 300,
                "uplinkOnly": 2,
                "downlinkOnly": 5,
                "statsUserUplink": true,
                "statsUserDownlink": true,
                "bufferSize": 10240
            }
        },
        "system": {
            "statsInboundUplink": true,
            "statsInboundDownlink": true,
            "statsOutboundUplink": true,
            "statsOutboundDownlink": true
        }
    }
}

RESTful API Usage

  1. GET: uri: /api/v1/statssys
    • return json
  2. GET: uri: /api/v1/statsquery/:pattern
    • return json
    • e.g.
      • curl "http://127.0.0.1:8080/api/v1/statsquery"
        • return all
      • curl "http://127.0.0.1:8080/api/v1/statsquery/outbound>>>proxy>>>traffic>>>downlink"
        • return counter outbound>>>proxy>>>traffic>>>downlink
  3. GET: uri: /api/v1/stats/:name
    • return json
      • e.g. curl "http://127.0.0.1:8080/api/v1/stats/outbound>>>proxy>>>traffic>>>downlink"
  4. DELETE: uri: /api/v1/inbounds/:tag
  5. DELETE: uri: /api/v1/outbounds/:tag
  6. POST: uri: /api/v1/inbounds, header: "Content-Type: application/json"
    • e.g.
    curl \
    -X POST
    -H "Content-Type: application/json" \
    -D '
    {
        "tag": "http-test",
        "port": 1080,
        "protocol": "http",
        "settings": {}
    }
    ' \
    http://127.0.0.1:8080/api/v1/inbounds
  1. POST: uri: /api/v1/outbounds, header: "Content-Type: application/json"
    • e.g.
    curl \
    -X POST
    -H "Content-Type: application/json" \
    -D '
    {
        "tag": "proxy-test",
        "protocol": "VLESS",
        "settings": {
            "vnext": [
                {
                    "address": "192.168.1.1",
                    "port": 443,
                    "users": [
                        {
                            "id": "00000000-0000-0000-0000-000000000000",
                            "alterId": 0,
                            "email": "[email protected]",
                            "security": "none",
                            "encryption": "none",
                            "flow": "xtls-rprx-splice"
                        }
                    ]
                }
            ],
            "servers": null,
            "response": null
        },
        "streamSettings": {
            "network": "tcp",
            "security": "xtls",
            "xtlsSettings": {
                "allowInsecure": false,
                "serverName": "foo.bar"
            }
        },
        "mux": {
            "enabled": false
        }
    }
    ' \
    http://127.0.0.1:8080/api/v1/outbounds

@CerteKim CerteKim mentioned this pull request Mar 12, 2021
@smallprogram
Copy link

这个PR何时才能Merge......

@RPRX
Copy link
Member

RPRX commented Mar 25, 2021

@smallprogram v1.5.0 前

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants