Skip to content

Commit

Permalink
ci: fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Jan 18, 2025
1 parent 074d941 commit 97159bb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
9 changes: 5 additions & 4 deletions docs/plugins/library/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
use `require("http")` to access it. For example:

**Usage**

```lua
local http = require("http")
--- get request, do not use this request to download files!!!
local resp, err = http.get({
url = "http://ip.jsontest.com/",
url = "https://httpbin.org/json",
headers = {
['Host'] = "localhost"
}
Expand All @@ -17,11 +18,11 @@ local resp, err = http.get({
assert(err == nil)
assert(resp.status_code == 200)
assert(resp.headers['Content-Type'] == 'application/json')
assert(resp.body == '{"ip": "xxx.xxx.xxx.xxx"}')
assert(resp.body == 'xxxxx')

--- head request
resp, err = http.head({
url = "http://ip.jsontest.com/",
url = "https://httpbin.org/json",
headers = {
['Host'] = "localhost"
}
Expand All @@ -37,4 +38,4 @@ err = http.download_file({
}, "/usr/local/file")
assert(err == nil, [[must be nil]] )

```
```
16 changes: 8 additions & 8 deletions docs/zh-hans/plugins/library/http.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Http标准库

`vfox`提供了一个简单的http能力,当前支持`Get``Head`两种请求类型,以及文件下载。
# Http 标准库

`vfox`提供了一个简单的 http 能力,当前支持`Get``Head`两种请求类型,以及文件下载。

**使用**

```lua
local http = require("http")
--- get 请求, 不要用此请求进行文件下载!!!
local resp, err = http.get({
url = "http://ip.jsontest.com/",
url = "https://httpbin.org/json",
headers = {
['Host'] = "localhost"
}
Expand All @@ -17,11 +17,11 @@ local resp, err = http.get({
assert(err == nil)
assert(resp.status_code == 200)
assert(resp.headers['Content-Type'] == 'application/json')
assert(resp.body == '{"ip": "xxx.xxx.xxx.xxx"}')
assert(resp.body == 'xxxxxxxx')

--- head 请求
--- head 请求
resp, err = http.head({
url = "http://ip.jsontest.com/",
url = "https://httpbin.org/json",
headers = {
['Host'] = "localhost"
}
Expand All @@ -37,4 +37,4 @@ err = http.download_file({
}, "/usr/local/file")
assert(err == nil, [[must be nil]] )

```
```
9 changes: 5 additions & 4 deletions internal/module/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ package http

import (
"fmt"
"github.com/schollz/progressbar/v3"
"github.com/version-fox/vfox/internal/config"
lua "github.com/yuin/gopher-lua"
"io"
"net/http"
"net/url"
"os"
"path/filepath"

"github.com/schollz/progressbar/v3"
"github.com/version-fox/vfox/internal/config"
lua "github.com/yuin/gopher-lua"
)

type Module struct {
Expand All @@ -41,7 +42,7 @@ type Module struct {
// local http = require("http")
//
// http.get({
// url = "http://ip.jsontest.com/"
// url = "https://httpbin.org/json"
// }) return (response, error)
//
// response : {
Expand Down
11 changes: 6 additions & 5 deletions internal/module/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
package http

import (
"github.com/version-fox/vfox/internal/util"
"os"
"runtime"
"testing"

"github.com/version-fox/vfox/internal/util"

"github.com/version-fox/vfox/internal/config"
lua "github.com/yuin/gopher-lua"
)
Expand All @@ -36,10 +37,10 @@ func TestWithConfig(t *testing.T) {
assert(type(http) == "table")
assert(type(http.get) == "function")
local resp, err = http.get({
url = "http://ip.jsontest.com/"
url = "https://httpbin.org/json"
})
print(err)
assert(err == 'Get "http://ip.jsontest.com/": proxyconnect tcp: dial tcp 127.0.0.1:80: connect: connection refused')
assert(err == 'Get "https://httpbin.org/json": proxyconnect tcp: dial tcp 127.0.0.1:80: connect: connection refused')
`
s := lua.NewState()
defer s.Close()
Expand All @@ -58,7 +59,7 @@ func TestGetRequest(t *testing.T) {
assert(type(http) == "table")
assert(type(http.get) == "function")
local resp, err = http.get({
url = "http://ip.jsontest.com/"
url = "https://httpbin.org/json"
})
assert(err == nil)
assert(resp.status_code == 200)
Expand All @@ -73,7 +74,7 @@ func TestHeadRequest(t *testing.T) {
assert(type(http) == "table")
assert(type(http.get) == "function")
local resp, err = http.head({
url = "http://ip.jsontest.com/"
url = "https://httpbin.org/json"
})
assert(err == nil)
assert(resp.status_code == 200)
Expand Down

0 comments on commit 97159bb

Please sign in to comment.