很长一段时间,浏览器每个主机最多使用6个并发HTTP 1.1连接来从网页中检索资产.远远超出这个黄金标准被认为是DOS并让你被禁止服务器.
现在有HTTP/2,我们可以在一个连接上复用许多HTTP请求.我们是否仍应对我们在连接上复用的并发请求数量使用类似的限制,以防止服务器过载?或者在单个连接上复用更多请求是否有害?
任何人都知道浏览器使用每台主机和HTTP/2服务器的每个连接限制了什么?
我目前正在尝试使用nghttp2
构建多部分消息.该消息应该如下所示.
我应该使用nghttp2_submit_request
(here)函数,nva
作为我的HTTP/2标头,以及nghttp2_data_provider *data_prd
我的数据.但是,我仍然不明白我究竟能创建两条消息(带有两个消息头).
更新:
我可以在源代码中描述我的想法吗?请看下面.在这里,我nghttp2_data_provider
用来打开一个音频文件,然后写入缓冲区.
ssize_t data_prd_read_callback(
nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length,
uint32_t *data_flags, nghttp2_data_source *source, void *user_data)
{
printf("[INFO] C ----------------------------> S (DATA post body), length:%zu\n", length);
int fd = source->fd;
ssize_t r;
// writting my opened audio file into buffer
while ((r = read(fd, buf, length)) == -1 && errno == EINTR);
printf("stream_id:%d, nread:%zu\r\n", stream_id, r);
return nread;
}
void submit_postAudio(http2_session_data *session_data) {
int32_t …
Run Code Online (Sandbox Code Playgroud) 我使用的CentOS 6.2,我需要在服务器请求一个使用卷曲--http2.0,但我是有7.19.6,看后http://curl.haxx.se/docs/manpage.html给我认为--http2.0选项仅支持curl 7.33.0,所以为了解决这个问题,我按照http://www.linuxfromscratch.org/blfs/view/svn中的步骤安装了curl 7.33.0 . /basicnet/curl.html 安装curl后,我试图使用它,但它仍然给我错误curl(1):不支持的协议,我已经检查了我的卷曲版本使用:curl --version这是给我 :
curl 7.33.0 (x86_64-unknown-linux-gnu) libcurl/7.33.0 OpenSSL/1.0.0 zlib/1.2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL libz
Run Code Online (Sandbox Code Playgroud)
我需要使用这个--http2.0,但没有得到任何我能做到的事情吗?由于curl 7.19已经安装并且我重新安装了更高版本的curl,这是否有任何问题?
具有服务器推送支持的Jetty的HTTP/2客户端已在Jetty 9.3 RC(Link)中实现.但是,我没有找到任何与此相关的文档或示例代码.可以任何人提供示例代码,例如从该站点接收推送的资源:https://nghttp2.org(已启用http2服务器推送的公共服务器)
---更新1 --- 我试图测试这个文件,正如sbordet所说的那样.但是,在执行此行之后
mvn compile exec:java
Run Code Online (Sandbox Code Playgroud)
我遇到了这个错误
[INFO] --- exec-maven-plugin:1.4.0:java (default-cli) @ http2client ---
2015-05-05 01:52:47.808:INFO::com.example.Client.main(): Logging initialized @3096ms
[WARNING]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.TimeoutException
at org.eclipse.jetty.util.FuturePromise.get(FuturePromise.java:130)
at com.example.Client.main(Client.java:55)
... 6 more
Run Code Online (Sandbox Code Playgroud)
这是我的 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>http2client</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>http2client</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-client</artifactId>
<version>9.3.0.M2</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty.alpn</groupId>
<artifactId>alpn-boot</artifactId> …
Run Code Online (Sandbox Code Playgroud) 我目前正在使用SwiftNIO和SwiftNIOHTTP2 beta在Swift中使用简单的HTTP2客户端.我的实现看起来像这样:
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let bootstrap = ClientBootstrap(group: group)
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
.channelInitializer { channel in
channel.pipeline.add(handler: HTTP2Parser(mode: .client)).then {
let multiplexer = HTTP2StreamMultiplexer { (channel, streamID) -> EventLoopFuture<Void> in
return channel.pipeline.add(handler: HTTP2ToHTTP1ClientCodec(streamID: streamID, httpProtocol: .https))
}
return channel.pipeline.add(handler: multiplexer)
}
}
defer {
try! group.syncShutdownGracefully()
}
let url = URL(string: "https://strnmn.me")!
_ = try bootstrap.connect(host: url.host!, port: url.port ?? 443)
.wait()
Run Code Online (Sandbox Code Playgroud)
不幸的是,连接始终失败并出现错误:
nghttp2错误:当我们期望SETTINGS帧时,远程对等体返回了意外数据.也许,peer不能正确支持HTTP/2.
但是,从命令行使用nghttp2连接和发出一个简单的请求可以正常工作.
$ nghttp -vn https://strnmn.me
[ 0.048] Connected
The negotiated protocol: h2 …
Run Code Online (Sandbox Code Playgroud) 我想将 http/2 与 cURL 一起使用。首先,当我尝试此操作时出现错误curl --http2 https://http2.akamai.com/
- “协议不支持”。我安装了 nghttp2 并重新安装了 cURL,就像这里描述的那样。错误消失了,我现在可以获取数据了curl --http2
。但是页面https://http2.akamai.com/告诉我“此浏览器未启用 HTTP/2”,而在 chrome 中或直接通过 nghttp2 则显示“您现在正在使用 HTTP/2!” 。
我使用的是 mac os x 并通过 homebrew 安装了最新版本中的所有依赖项。我在这里下载了curl源代码(7.41)。
我已经阅读了一些HTTP/2 rfc7540规范,我还不完全了解HTTP/2协议中WINDOW_UPDATE和SETTINGS帧之间的区别是什么?
我不知道为什么会出现这种错误.
我在centos 7上使用nghttp2.
我的centos支持c ++ 17
我忘记了任何选择吗?
请帮帮我.
谢谢.
usr/include/c++/4.8.2/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support for the \ ^ In file included from util.h:52:0, from util.cc:25: template.h:44:19: warning: variadic templates only available with -std=c++11 or -std=gnu++11 [enabled by default] template <typename... T> ^ template.h:45:1: …