-
Notifications
You must be signed in to change notification settings - Fork 161
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 replace invalid http header character #26
Conversation
@leoner, thanks for your PR! By analyzing the history of the files in this pull request, we identified @fengmk2, @dead-horse and @alsotang to be potential reviewers. |
benchmark 加上一个真实登录太的headers做测试吧 |
863400c
to
c85ff0d
Compare
Codecov Report
@@ Coverage Diff @@
## master #26 +/- ##
==========================================
+ Coverage 98.97% 99.02% +0.05%
==========================================
Files 12 12
Lines 292 307 +15
==========================================
+ Hits 289 304 +15
Misses 3 3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26 +/- ##
==========================================
+ Coverage 98.97% 99.02% +0.05%
==========================================
Files 12 12
Lines 292 307 +15
==========================================
+ Hits 289 304 +15
Misses 3 3
Continue to review full report at Codecov.
|
benchmark/string.js
Outdated
const headers= {}; | ||
const headers_invalid = {}; | ||
|
||
headers['Host'] = 'my.alipay.com'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fengmk2 加上了, cookie 那里把一些内容随机替换了下.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成 my.foo.com
0.12 不支持 const https://travis-ci.org/node-modules/utility/jobs/201152011 |
这么不通用的一个函数。。。怎么不新建一个包 |
c85ff0d
to
4583d86
Compare
改好了,去掉 const, 都改成 var了. |
@alsotang 太通用的,你要做 http proxy,都得使用这个函数 |
lib/string.js
Outdated
* @param {String} str | ||
* @return {Object} | ||
*/ | ||
exports.replaceInvalidHttpHeaderChar = function replaceInvalidHttpHeaderChar(val) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
增加一个 replacement
参数,默认是' '
,这样允许使用者填充自定义参数
invalid = true; | ||
} | ||
|
||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里肯定也不支持
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那测试用例为啥不影响, 我看测试用例大量用了 const 和 () =>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
测试用例用了 ava 吧,ava 用 babel 编译了
lib/string.js
Outdated
* so take care when making changes to the implementation so that the source | ||
* code size does not exceed v8's default max_inlined_source_size setting. | ||
**/ | ||
const validHdrChars = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test/string.test.js
Outdated
const s7 = '111你1好0'; | ||
const s8 = '1111你1好0'; | ||
|
||
t.is(utils.replaceInvalidHttpHeaderChar(s0).val, s0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还需要判断 invalid 的值
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
invalid = true; | ||
} | ||
|
||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那测试用例为啥不影响, 我看测试用例大量用了 const 和 () =>
invalid = true; | ||
} | ||
|
||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4583d86
to
9f55344
Compare
@leoner 因为单测是 ava 跑的,它经过了 babel 编译。 |
9f55344
to
5596981
Compare
5596981
to
4a939fc
Compare
好, 现在都过了. |
// utility.replaceInvalidHttpHeaderChar(str1_1000) x 29,391 ops/sec ±1.41% (90 runs sampled) | ||
// utility.replaceInvalidHttpHeaderChar(str2_1000) x 27,842 ops/sec ±1.29% (83 runs sampled) | ||
// utility.replaceInvalidHttpHeaderChar(str3_1000) x 26,905 ops/sec ±1.63% (85 runs sampled) | ||
// utility.relaceInvalidHttpHeaderChar(real_headers) x 85,277 ops/sec ±1.34% (83 runs sampled) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
又是一个性能瓶颈点
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
恩, 目前我们这里执行过了, 到了 http 模块中, 还是会在执行一遍.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node 里面不知道为啥那么严格, 直接异常了.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
1.10.0 |
No description provided.