-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support httpclient mock on allowH2 = true
- Loading branch information
Showing
26 changed files
with
838 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Publish Any Commit | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- run: corepack enable | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build | ||
run: npm run prepublishOnly --if-present | ||
|
||
- run: npx pkg-pr-new publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = function() { | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
getResult(result) { | ||
return { | ||
body: result, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
module.exports = function* () { | ||
const stream = yield this.getFileStream(); | ||
const fields = stream.fields; | ||
this.body = { | ||
fields, | ||
filename: stream.filename, | ||
user: this.user, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
'use strict'; | ||
|
||
exports.get = function* () { | ||
this.body = { | ||
cookieValue: this.getCookie('foo') || undefined, | ||
cookiesValue: this.cookies.get('foo') || undefined, | ||
sessionValue: this.session.foo, | ||
}; | ||
}; | ||
|
||
exports.post = function* () { | ||
this.body = 'done'; | ||
}; | ||
|
||
exports.hello = function* () { | ||
this.body = 'hi'; | ||
}; | ||
|
||
exports.service = function* () { | ||
this.body = { | ||
foo1: yield this.service.foo.get(), | ||
foo2: yield this.service.bar.foo.get(), | ||
foo3: this.service.foo.getSync(), | ||
thirdService: yield this.service.third.bar.foo.get(), | ||
}; | ||
}; | ||
|
||
exports.serviceOld = function* () { | ||
this.body = yield this.service.old.test(); | ||
}; | ||
|
||
exports.header = function* () { | ||
this.body = { | ||
header: this.get('customheader'), | ||
}; | ||
}; | ||
|
||
exports.urllib = function* () { | ||
const url = 'http://' + this.host; | ||
const method = this.query.method || 'request'; | ||
const data = this.query.data ? JSON.parse(this.query.data) : undefined; | ||
const dataType = this.query.dataType; | ||
const foo = this.query.foo; | ||
let requestUrl = url + (this.query.mock_url || '/mock_url'); | ||
if (foo) { | ||
requestUrl = `${requestUrl}?foo=${foo}`; | ||
} | ||
let r = this.app.httpclient[method](requestUrl, { | ||
dataType, | ||
data, | ||
}); | ||
if (method === 'request') r = r.then(d => d); | ||
const r1 = yield r; | ||
const r2 = yield this.app.httpclient[method](requestUrl, { | ||
method: 'POST', | ||
dataType, | ||
data, | ||
headers: { | ||
'x-custom': 'custom', | ||
}, | ||
}); | ||
this.body = { | ||
get: Buffer.isBuffer(r1.data) ? r1.data.toString() : r1.data, | ||
post: Buffer.isBuffer(r2.data) ? r2.data.toString() : r2.data, | ||
}; | ||
}; | ||
|
||
exports.streaming = async ctx => { | ||
const url = 'http://' + ctx.host; | ||
const response = await ctx.httpclient.request(url + '/mock_url', { | ||
method: 'GET', | ||
streaming: true, | ||
}); | ||
ctx.status = response.status; | ||
ctx.body = response.res; | ||
}; | ||
|
||
exports.mockUrlGet = function* () { | ||
const foo = this.query.foo; | ||
if (foo) { | ||
this.body = `url get with foo: ${foo}`; | ||
return; | ||
} | ||
this.body = 'url get'; | ||
}; | ||
|
||
exports.mockUrlPost = function* () { | ||
this.body = 'url post'; | ||
}; | ||
|
||
exports.mockUrllibHeaders = function* () { | ||
const url = 'http://' + this.host; | ||
const method = this.query.method || 'request'; | ||
const res = yield this.app.httpclient[method](url + '/mock_url'); | ||
this.body = res.headers; | ||
}; | ||
|
||
exports.dataType = function* () { | ||
const url = 'http://' + this.host; | ||
const res = yield this.app.httpclient.request(url + '/mock_url', { | ||
dataType: 'json', | ||
}); | ||
this.body = res.data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = function* () { | ||
this.session.save(); | ||
this.body = this.session; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
exports.get = function* () { | ||
this.body = this.user; | ||
}; | ||
|
||
exports.post = function* () { | ||
this.body = { | ||
user: this.user, | ||
params: this.request.body, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
mockDevice(obj) { | ||
obj.mock = true; | ||
return obj; | ||
}, | ||
|
||
* mockGenerator(obj) { | ||
obj.mock = true; | ||
return obj; | ||
}, | ||
|
||
mockPromise(obj) { | ||
obj.mock = true; | ||
return Promise.resolve(obj); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = app => { | ||
app.get('home', '/', app.controller.home.get); | ||
app.get('/hello', app.controller.home.hello); | ||
app.get('/service', app.controller.home.service); | ||
app.get('/service/old', app.controller.home.serviceOld); | ||
app.get('/header', app.controller.home.header); | ||
app.get('/urllib', app.controller.home.urllib); | ||
app.get('/mock_url', app.controller.home.mockUrlGet); | ||
app.get('/mock_url2', app.controller.home.mockUrlGet); | ||
app.post('/mock_url', app.controller.home.mockUrlPost); | ||
app.post('/mock_url2', app.controller.home.mockUrlPost); | ||
app.get('/mock_urllib', app.controller.home.mockUrllibHeaders); | ||
app.get('/data_type', app.controller.home.dataType); | ||
app.get('session', '/session', app.controller.session); | ||
|
||
app.post('/', app.controller.home.post); | ||
|
||
app.get('/user', app.controller.user.get); | ||
app.post('/user', app.controller.user.post); | ||
app.post('/file', app.controller.file); | ||
|
||
app.get('/streaming', 'home.streaming'); | ||
}; |
Oops, something went wrong.