Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
bb8e79c8
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bb8e79c8
编写于
11月 30, 2016
作者:
J
Johannes Rieken
提交者:
GitHub
11月 30, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16211 from Microsoft/joh/xhr
Use XmlHttpRequest when making requests from a renderer
上级
690a8118
10ae5b4b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
112 addition
and
9 deletion
+112
-9
src/vs/base/node/request.ts
src/vs/base/node/request.ts
+12
-4
src/vs/platform/request/electron-browser/requestService.ts
src/vs/platform/request/electron-browser/requestService.ts
+95
-0
src/vs/platform/request/node/requestService.ts
src/vs/platform/request/node/requestService.ts
+3
-3
src/vs/workbench/electron-browser/shell.ts
src/vs/workbench/electron-browser/shell.ts
+2
-2
未找到文件。
src/vs/base/node/request.ts
浏览文件 @
bb8e79c8
...
...
@@ -31,11 +31,19 @@ export interface IRequestOptions {
}
export
interface
IRequestContext
{
req
:
http
.
ClientRequest
;
res
:
http
.
ClientResponse
;
// req: http.ClientRequest;
// res: http.ClientResponse;
res
:
{
headers
:
{
[
n
:
string
]:
string
};
statusCode
?:
number
;
};
stream
:
Stream
;
}
export
interface
IRequestFunction
{
(
options
:
IRequestOptions
):
TPromise
<
IRequestContext
>
;
}
export
function
request
(
options
:
IRequestOptions
):
TPromise
<
IRequestContext
>
{
let
req
:
http
.
ClientRequest
;
...
...
@@ -71,7 +79,7 @@ export function request(options: IRequestOptions): TPromise<IRequestContext> {
stream
=
stream
.
pipe
(
createGunzip
());
}
c
({
re
q
,
re
s
,
stream
});
c
({
res
,
stream
});
}
});
...
...
@@ -144,4 +152,4 @@ export function asJson<T>(context: IRequestContext): TPromise<T> {
context
.
stream
.
on
(
'
end
'
,
()
=>
c
(
JSON
.
parse
(
buffer
.
join
(
''
))));
context
.
stream
.
on
(
'
error
'
,
e
);
});
}
\ No newline at end of file
}
src/vs/platform/request/electron-browser/requestService.ts
0 → 100644
浏览文件 @
bb8e79c8
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IRequestOptions
,
IRequestContext
,
IRequestFunction
}
from
'
vs/base/node/request
'
;
import
{
Readable
}
from
'
stream
'
;
import
{
RequestService
as
NodeRequestService
}
from
'
vs/platform/request/node/requestService
'
;
/**
* This service exposes the `request` API, while using the global
* or configured proxy settings.
*/
export
class
RequestService
extends
NodeRequestService
{
request
(
options
:
IRequestOptions
):
TPromise
<
IRequestContext
>
{
return
super
.
request
(
options
,
xhrRequest
);
}
}
class
ArryBufferStream
extends
Readable
{
private
_buffer
:
Buffer
;
private
_offset
:
number
;
private
_length
:
number
;
constructor
(
arraybuffer
:
ArrayBuffer
)
{
super
();
this
.
_buffer
=
new
Buffer
(
new
Uint8Array
(
arraybuffer
));
this
.
_offset
=
0
;
this
.
_length
=
this
.
_buffer
.
length
;
}
_read
(
size
:
number
)
{
if
(
this
.
_offset
<
this
.
_length
)
{
this
.
push
(
this
.
_buffer
.
slice
(
this
.
_offset
,
(
this
.
_offset
+
size
)));
this
.
_offset
+=
size
;
}
else
{
this
.
push
(
null
);
}
}
}
export
const
xhrRequest
:
IRequestFunction
=
(
options
:
IRequestOptions
):
TPromise
<
IRequestContext
>
=>
{
const
xhr
=
new
XMLHttpRequest
();
return
new
TPromise
<
IRequestContext
>
((
resolve
,
reject
)
=>
{
xhr
.
open
(
options
.
type
,
options
.
url
,
true
,
options
.
user
,
options
.
password
);
setRequestHeaders
(
xhr
,
options
);
xhr
.
responseType
=
'
arraybuffer
'
;
xhr
.
onerror
=
reject
;
xhr
.
onload
=
(
e
)
=>
{
resolve
({
res
:
{
statusCode
:
xhr
.
status
,
headers
:
getResponseHeaders
(
xhr
)
},
stream
:
new
ArryBufferStream
(
xhr
.
response
)
});
};
xhr
.
send
(
options
.
data
);
return
null
;
},
()
=>
{
// cancel
xhr
.
abort
();
});
};
function
setRequestHeaders
(
xhr
:
XMLHttpRequest
,
options
:
IRequestOptions
):
void
{
if
(
options
.
headers
)
{
for
(
let
k
in
options
.
headers
)
{
try
{
xhr
.
setRequestHeader
(
k
,
options
.
headers
[
k
]);
}
catch
(
e
)
{
console
.
warn
(
e
);
}
}
}
}
function
getResponseHeaders
(
xhr
:
XMLHttpRequest
):
{
[
name
:
string
]:
string
}
{
const
headers
:
{
[
name
:
string
]:
string
}
=
Object
.
create
(
null
);
for
(
const
line
of
xhr
.
getAllResponseHeaders
().
split
(
/
\r\n
|
\n
|
\r
/g
))
{
if
(
line
)
{
const
idx
=
line
.
indexOf
(
'
:
'
);
headers
[
line
.
substr
(
0
,
idx
).
trim
().
toLowerCase
()]
=
line
.
substr
(
idx
+
1
).
trim
();
}
}
return
headers
;
}
src/vs/platform/request/node/requestService.ts
浏览文件 @
bb8e79c8
...
...
@@ -7,7 +7,7 @@
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
assign
}
from
'
vs/base/common/objects
'
;
import
{
IRequestOptions
,
IRequestContext
,
request
}
from
'
vs/base/node/request
'
;
import
{
IRequestOptions
,
IRequestContext
,
IRequestFunction
,
request
}
from
'
vs/base/node/request
'
;
import
{
getProxyAgent
}
from
'
vs/base/node/proxy
'
;
import
{
IRequestService
,
IHTTPConfiguration
}
from
'
vs/platform/request/node/request
'
;
import
{
IConfigurationService
,
IConfigurationServiceEvent
}
from
'
vs/platform/configuration/common/configuration
'
;
...
...
@@ -42,7 +42,7 @@ export class RequestService implements IRequestService {
this
.
authorization
=
config
.
http
&&
config
.
http
.
proxyAuthorization
;
}
request
(
options
:
IRequestOptions
):
TPromise
<
IRequestContext
>
{
request
(
options
:
IRequestOptions
,
requestFn
:
IRequestFunction
=
request
):
TPromise
<
IRequestContext
>
{
const
{
proxyUrl
,
strictSSL
}
=
this
;
options
.
agent
=
options
.
agent
||
getProxyAgent
(
options
.
url
,
{
proxyUrl
,
strictSSL
});
...
...
@@ -52,6 +52,6 @@ export class RequestService implements IRequestService {
options
.
headers
=
assign
(
options
.
headers
||
{},
{
'
Proxy-Authorization
'
:
this
.
authorization
});
}
return
request
(
options
);
return
request
Fn
(
options
);
}
}
src/vs/workbench/electron-browser/shell.ts
浏览文件 @
bb8e79c8
...
...
@@ -37,7 +37,7 @@ import { WindowsChannelClient } from 'vs/platform/windows/common/windowsIpc';
import
{
WindowService
}
from
'
vs/platform/windows/electron-browser/windowService
'
;
import
{
MessageService
}
from
'
vs/workbench/services/message/electron-browser/messageService
'
;
import
{
IRequestService
}
from
'
vs/platform/request/node/request
'
;
import
{
RequestService
}
from
'
vs/platform/request/
node
/requestService
'
;
import
{
RequestService
}
from
'
vs/platform/request/
electron-browser
/requestService
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
SearchService
}
from
'
vs/workbench/services/search/node/searchService
'
;
import
{
LifecycleService
}
from
'
vs/workbench/services/lifecycle/electron-browser/lifecycleService
'
;
...
...
@@ -560,4 +560,4 @@ export class WorkbenchShell {
// Container
$
(
this
.
container
).
empty
();
}
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录