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 replace invalid http header character #26

Merged
merged 1 commit into from
Feb 14, 2017

Conversation

leoner
Copy link
Contributor

@leoner leoner commented Feb 13, 2017

No description provided.

@mention-bot
Copy link

@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.

@fengmk2
Copy link
Member

fengmk2 commented Feb 14, 2017

benchmark 加上一个真实登录太的headers做测试吧

@leoner leoner force-pushed the feat-add-replace-invalid-char branch from 863400c to c85ff0d Compare February 14, 2017 02:45
@codecov
Copy link

codecov bot commented Feb 14, 2017

Codecov Report

Merging #26 into master will increase coverage by 0.05%.
The diff coverage is 100%.

@@            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
Impacted Files Coverage Δ
lib/string.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e05ef3...c85ff0d. Read the comment docs.

@codecov
Copy link

codecov bot commented Feb 14, 2017

Codecov Report

Merging #26 into master will increase coverage by 0.05%.
The diff coverage is 100%.

@@            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
Impacted Files Coverage Δ
lib/string.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e05ef3...4a939fc. Read the comment docs.

const headers= {};
const headers_invalid = {};

headers['Host'] = 'my.alipay.com';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fengmk2 加上了, cookie 那里把一些内容随机替换了下.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成 my.foo.com

@fengmk2
Copy link
Member

fengmk2 commented Feb 14, 2017

@fengmk2 fengmk2 self-requested a review February 14, 2017 03:01
@alsotang
Copy link
Member

这么不通用的一个函数。。。怎么不新建一个包

@leoner leoner force-pushed the feat-add-replace-invalid-char branch from c85ff0d to 4583d86 Compare February 14, 2017 03:46
@leoner
Copy link
Contributor Author

leoner commented Feb 14, 2017

改好了,去掉 const, 都改成 var了.

@fengmk2
Copy link
Member

fengmk2 commented Feb 14, 2017

@alsotang 太通用的,你要做 http proxy,都得使用这个函数

lib/string.js Outdated
* @param {String} str
* @return {Object}
*/
exports.replaceInvalidHttpHeaderChar = function replaceInvalidHttpHeaderChar(val) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加一个 replacement 参数,默认是' ',这样允许使用者填充自定义参数

invalid = true;
}

return {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里肯定也不支持

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那测试用例为啥不影响, 我看测试用例大量用了 const 和 () =>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member

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 = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

好奇怪, 我在提交下.

const s7 = '111你1好0';
const s8 = '1111你1好0';

t.is(utils.replaceInvalidHttpHeaderChar(s0).val, s0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还需要判断 invalid 的值

Copy link
Contributor Author

@leoner leoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

我ka看我们给的例子, 直接就是用 const, 要不我们改下不支持 0.12 了?

invalid = true;
}

return {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那测试用例为啥不影响, 我看测试用例大量用了 const 和 () =>

invalid = true;
}

return {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@leoner leoner force-pushed the feat-add-replace-invalid-char branch from 4583d86 to 9f55344 Compare February 14, 2017 06:18
@fengmk2
Copy link
Member

fengmk2 commented Feb 14, 2017

@leoner 因为单测是 ava 跑的,它经过了 babel 编译。

@leoner leoner force-pushed the feat-add-replace-invalid-char branch from 9f55344 to 5596981 Compare February 14, 2017 06:24
@leoner leoner force-pushed the feat-add-replace-invalid-char branch from 5596981 to 4a939fc Compare February 14, 2017 06:26
@leoner
Copy link
Contributor Author

leoner commented Feb 14, 2017

好, 现在都过了.

// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

又是一个性能瓶颈点

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

恩, 目前我们这里执行过了, 到了 http 模块中, 还是会在执行一遍.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node 里面不知道为啥那么严格, 直接异常了.

Copy link
Member

@fengmk2 fengmk2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fengmk2 fengmk2 merged commit 387babc into master Feb 14, 2017
@fengmk2 fengmk2 deleted the feat-add-replace-invalid-char branch February 14, 2017 07:46
@fengmk2
Copy link
Member

fengmk2 commented Feb 14, 2017

1.10.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.

5 participants