Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
8edf0994
D
deno
项目概览
张重言
/
deno
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
deno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
8edf0994
编写于
9月 18, 2020
作者:
R
Ryan Dahl
提交者:
GitHub
9月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
publish deno_fetch during CI (#7557)
上级
93e8e59a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
23 addition
and
32 deletion
+23
-32
.github/workflows/ci.yml
.github/workflows/ci.yml
+3
-0
cli/main.rs
cli/main.rs
+2
-0
op_crates/fetch/Cargo.toml
op_crates/fetch/Cargo.toml
+1
-1
op_crates/fetch/README.md
op_crates/fetch/README.md
+1
-0
op_crates/fetch/lib.rs
op_crates/fetch/lib.rs
+16
-31
未找到文件。
.github/workflows/ci.yml
浏览文件 @
8edf0994
...
...
@@ -231,6 +231,9 @@ jobs:
cd ../op_crates/web
cargo publish
sleep 30
cd ../op_crates/fetch
cargo publish
sleep 30
cd ../../cli
sleep 30
cargo publish
cli/main.rs
浏览文件 @
8edf0994
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
#![deny(warnings)]
#[macro_use]
extern
crate
lazy_static
;
#[macro_use]
...
...
op_crates/fetch/Cargo.toml
浏览文件 @
8edf0994
...
...
@@ -4,7 +4,7 @@
name
=
"deno_fetch"
version
=
"0.1.0"
edition
=
"2018"
description
=
"
fetch Web API
"
description
=
"
provides fetch Web API to deno_core
"
authors
=
[
"the Deno authors"
]
license
=
"MIT"
readme
=
"README.md"
...
...
op_crates/fetch/README.md
0 → 100644
浏览文件 @
8edf0994
This crate provides the web standard fetch API to
`deno_core`
.
op_crates/fetch/lib.rs
浏览文件 @
8edf0994
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
#![deny(warnings)]
use
deno_core
::
error
::
bad_resource_id
;
use
deno_core
::
error
::
type_error
;
use
deno_core
::
error
::
AnyError
;
...
...
@@ -14,10 +16,9 @@ use deno_core::BufVec;
use
deno_core
::
JsRuntime
;
use
deno_core
::
OpState
;
use
deno_core
::
ZeroCopyBuf
;
use
reqwest
::
header
::
HeaderMap
;
use
reqwest
::
header
::
HeaderName
;
use
reqwest
::
header
::
HeaderValue
;
use
reqwest
::
header
::
USER_AGENT
;
use
reqwest
::
redirect
::
Policy
;
use
reqwest
::
Client
;
use
reqwest
::
Method
;
...
...
@@ -31,6 +32,8 @@ use std::path::Path;
use
std
::
path
::
PathBuf
;
use
std
::
rc
::
Rc
;
pub
use
reqwest
;
// Re-export reqwest
pub
fn
init
(
isolate
:
&
mut
JsRuntime
)
{
let
manifest_dir
=
Path
::
new
(
env!
(
"CARGO_MANIFEST_DIR"
));
let
files
=
vec!
[
...
...
@@ -63,15 +66,6 @@ pub fn get_declaration() -> PathBuf {
PathBuf
::
from
(
env!
(
"CARGO_MANIFEST_DIR"
))
.join
(
"lib.deno_fetch.d.ts"
)
}
#[derive(Deserialize)]
#[serde(rename_all
=
"camelCase"
)]
struct
FetchArgs
{
method
:
Option
<
String
>
,
url
:
String
,
headers
:
Vec
<
(
String
,
String
)
>
,
client_rid
:
Option
<
u32
>
,
}
pub
async
fn
op_fetch
<
FP
>
(
state
:
Rc
<
RefCell
<
OpState
>>
,
args
:
Value
,
...
...
@@ -80,6 +74,15 @@ pub async fn op_fetch<FP>(
where
FP
:
FetchPermissions
+
'static
,
{
#[derive(Deserialize)]
#[serde(rename_all
=
"camelCase"
)]
struct
FetchArgs
{
method
:
Option
<
String
>
,
url
:
String
,
headers
:
Vec
<
(
String
,
String
)
>
,
client_rid
:
Option
<
u32
>
,
}
let
args
:
FetchArgs
=
serde_json
::
from_value
(
args
)
?
;
let
url
=
args
.url
;
...
...
@@ -181,23 +184,13 @@ pub async fn op_fetch_read(
let
mut
chunk_fut
=
response
.chunk
()
.boxed_local
();
let
r
=
ready!
(
chunk_fut
.poll_unpin
(
cx
))
?
;
if
let
Some
(
chunk
)
=
r
{
// TODO(ry) This is terribly inefficient. Make this zero-copy.
Ok
(
json!
({
"chunk"
:
&*
chunk
}))
.into
()
}
else
{
Ok
(
json!
({
"chunk"
:
null
}))
.into
()
}
});
f
.await
/*
// I'm programming this as I want it to be programmed, even though it might be
// incorrect, normally we would use poll_fn here. We need to make this await pattern work.
let chunk = response.chunk().await?;
if let Some(chunk) = chunk {
// TODO(ry) This is terribly inefficient. Make this zero-copy.
Ok(json!({ "chunk": &*chunk }))
} else {
Ok(json!({ "chunk": null }))
}
*/
}
struct
HttpClientResource
{
...
...
@@ -245,21 +238,13 @@ where
/// Create new instance of async reqwest::Client. This client supports
/// proxies and doesn't follow redirects.
fn
create_http_client
(
ca_file
:
Option
<&
str
>
)
->
Result
<
Client
,
AnyError
>
{
let
mut
headers
=
HeaderMap
::
new
();
// TODO(ry) set the verison correctly.
headers
.insert
(
USER_AGENT
,
format!
(
"Deno/{}"
,
"x.x.x"
)
.parse
()
.unwrap
());
let
mut
builder
=
Client
::
builder
()
.redirect
(
Policy
::
none
())
.default_headers
(
headers
)
.use_rustls_tls
();
let
mut
builder
=
Client
::
builder
()
.redirect
(
Policy
::
none
())
.use_rustls_tls
();
if
let
Some
(
ca_file
)
=
ca_file
{
let
mut
buf
=
Vec
::
new
();
File
::
open
(
ca_file
)
?
.read_to_end
(
&
mut
buf
)
?
;
let
cert
=
reqwest
::
Certificate
::
from_pem
(
&
buf
)
?
;
builder
=
builder
.add_root_certificate
(
cert
);
}
builder
.build
()
.map_err
(|
_
|
deno_core
::
error
::
generic_error
(
"Unable to build http client"
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录