Web.AsyncHTTP: Added Web.AsyncHTTP.#847
Conversation
|
Web.HTTP, Web.AsyncHTTP, Web.HTTP.Core に分割していこう、 Vitalize に失敗するようになっていたのでドラフトに戻しました。 |
|
Vitalize に失敗する問題を修正したのでドラフトを解除しました。 |
tsuyoshicho
left a comment
There was a problem hiding this comment.
@mikoto2000
確認できた改善点をコメントしました。
一部は修正必須と思うので(といってもtypo) Request changes にしました。
doc/vital/Web/AsyncHTTP.txt
Outdated
| This function requires one of the clients, "curl" or "wget". | ||
|
|
||
| Example: > | ||
| let s:AsyncHTP = vital#{plugin-name}#new().import('Web.AsyncHTTP') |
There was a problem hiding this comment.
| let s:AsyncHTP = vital#{plugin-name}#new().import('Web.AsyncHTTP') | |
| let s:AsyncHTTP = vital#{plugin-name}#new().import('Web.AsyncHTTP') |
typo fix
doc/vital/Web/AsyncHTTP.txt
Outdated
| python *Vital.Web.AsyncHTTP-client-python* | ||
| "python" as "python3" or "python2" auto select. | ||
| (High priority for "python3".) |
There was a problem hiding this comment.
Core で Python のファイル依存をはずしたりしてますが、こちらは利用できますか?
(CoreとPython利用の組み合せがどうなっているかを確認したい感じです)
もし、非同期との関係を考えて、サポートしないほうがいいのであれば、clientから外すのはアリと思いますので、記述を更新してもらえれば
There was a problem hiding this comment.
client の実体は、 HTTP, AsyncHTTP それぞれに存在しています。 (同期・非同期で実装が変わるため、それぞれで定義)
そのため、 python への依存は HTTP, AsyncHTTP それぞれから行っています。
ですので、 Core から python への依存は無くても大丈夫です。
Linux でですが、以下コードもエラーなく動きます。
let s:AsyncHTTP = vital#vital#import('Web.AsyncHTTP')
function! s:user_cb(response) abort
echomsg a:response
" => Web.HTTP と同じ形式の辞書
endfunction
call s:AsyncHTTP.request({
\ 'url': 'https://example.com',
\ 'user_cb': function('s:user_cb'),
\ 'clients': ['python2'],
\ })
call s:AsyncHTTP.request({
\ 'url': 'https://example.com',
\ 'user_cb': function('s:user_cb'),
\ 'clients': ['python3'],
\ })| function! s:_vital_loaded(V) abort | ||
| let s:V = a:V | ||
| let s:Prelude = s:V.import('Prelude') | ||
| let s:HTTP = s:V.import('Web.HTTP') |
There was a problem hiding this comment.
この依存関係は削除して、利用している機能は Core に置き、それを HTTP/AsyncHTTP が利用するように改善したほうがいいかと
| if has_key(s:clients.curl.errcode(), retcode) | ||
| throw 'vital: Web.HTTP: ' . s:clients.curl.errcode()[retcode] |
There was a problem hiding this comment.
せっかくのリファクタリングでもあるので
if s:clients.curl.errcode_has_key(retcode)
throw 'vital: Web.HTTP: ' . s:clients.curl.errcode(retcode)みたいなインタフェースにしてもいいかもしれませんね
errcode()が配列返すのがマストではないし、複数回利用するようなら、配列を初期化時にコピー相当でもいいので、
- コピーする
- 関数IFにする
のどちらかに寄せたほうがいいかなと
|
クライアントの指定方法を感知餓死していたため、 curl 以外の動作確認ができていない状態でした。 |
doc/vital/Web/AsyncHTTP.txt
Outdated
| parseHeader({headers}) *Vital.Web.HTTP.parseHeader()* | ||
| Parse {headers} list to a dictionary. | ||
| Duplicated fields are overwritten. | ||
|
|
||
| encodeURI({param}) *Vital.Web.HTTP.encodeURI()* | ||
| Encode params as URI query. | ||
|
|
||
| decodeURI({str}) *Vital.Web.HTTP.decodeURI()* | ||
| Decode string as URI params. | ||
|
|
||
| encodeURIComponent({str}) *Vital.Web.HTTP.encodeURIComponent()* | ||
| Encode param as URI components. |
There was a problem hiding this comment.
ここらへん AsyncHTTP になってないため、タグ重複エラーしてるみたいです。
正式で出すにあたって、修正しておいてください。
….HTTP and Web.AsyncHTTP.
…TTP to Web.HTTP.Core.
…eb.HTTP and Web.AsyncHTTP to Web.HTTP.Core
75a63a6 to
d14a759
Compare
|
リカバリ力が足りず、一から細かく刻みつつ再実装してしまいました。 |
doc/vital/Web/AsyncHTTP.txt
Outdated
| CLIENT *Vital.Web.AsyncHTTP-client* | ||
|
|
||
| The following can be used. | ||
| (TODO: More document. Especially about limitation.) |
There was a problem hiding this comment.
これは削除していいと思います。
また、Python系について、Pythonコマンド+スクリプトファイル+引数を AsyncProcess するという方法はなくはないので、一応TODOとしてPython3対応は将来予定として記載しておくのはどうでしょう?
(というか、そろそろ Python2 はもういい気がするな...w)
doc/vital/Web/AsyncHTTP.txt
Outdated
| "unixSocket" Default: (None) | ||
| Use --unix-sokect (only curl >= 7.40.0) | ||
|
|
||
| "user_cb" Default: (None) |
There was a problem hiding this comment.
ここだけスネークケースなのは微妙なので
| "user_cb" Default: (None) | |
| "userCallback" Default: (None) |
という引数にするのはどうでしょうか?
(そもそも Vim の記法としてどうかはあるけど)
| return result | ||
| endfunction | ||
|
|
||
| " public interface implements |
There was a problem hiding this comment.
うえの build 系なども利用はあるので、そちらも public な気がします。
逆に Core 内に閉じる関数もなくない気がしますが... (あったら、やるなら s:_hoge 化?)
なお関数の記法がいろいろなのは、内部処理だったからでしょうね、そこはとりあえずそのままでもいいと思います。
8ad4e39 to
78617a8
Compare
…named according to the naming convention.
| let settings = { | ||
| \ 'method': 'GET', | ||
| \ 'headers': {}, | ||
| \ 'client': ['python', 'curl', 'wget', 'python3', 'python2'], |
There was a problem hiding this comment.
クライアントは各実装依存となったので、こちらで固定で設定するのではなく
- request で追加設定する
- 引数を追加して、引数から client 設定する
などのAPI設計にしたようが良いと思われます。
tsuyoshicho
left a comment
There was a problem hiding this comment.
追加指摘です。
一応helpは
https://github.com/vim-jp/vimdoc-ja-working/wiki/Guide
のフォーマッタ設定を使うといいのですが、現状ちゃんと書いてあるから問題はないといえばないです
やたら差分でますが、調整の範囲ではあるという...
doc/vital/Web/AsyncHTTP.txt
Outdated
| Maintainer: mattn <mattn.jp@gmail.com> | ||
| thinca <thinca+vim@gmail.com> |
There was a problem hiding this comment.
ここは自分にしてください
(元にしたのが Web.HTTP と書いてもいいかもです
Co-authored-by: Tsuyoshi CHO <Tsuyoshi.CHO+github@Gmail.com>
82ad926 で対応いたしました。 |
Co-authored-by: Tsuyoshi CHO <Tsuyoshi.CHO+github@Gmail.com>
close #842