• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Redth/HttpTwo: A basic C# HTTP/2 client library

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

Redth/HttpTwo

开源软件地址:

https://github.com/Redth/HttpTwo

开源编程语言:

JavaScript 62.5%

开源软件介绍:

HttpTwo

A fully managed C# HTTP/2 client library implementation

The focus of this library is to bring enough HTTP/2 functionality to .NET for implementing the APNS (Apple Push Notification Service) provider API over HTTP/2 within PushSharp

Join the chat at https://gitter.im/Redth/HttpTwo

AppVeyor CI Status

It's currently not very well tested and lacks some implementation details.

What's working:

  • All frame types can be parsed and can be generated to send to a stream
  • HPack for frames that send headers (thanks to @ringostarr80)
  • Flow control is implemented in theory but not well tested
  • WINDOW_UPDATEs on the connection level (not yet per stream)
  • Simple requests should work

What's not working / not implemented:

  • Missing sending of WINDOW_UPDATE frames for streams, but streams aren't very long lived yet so it shouldn't be too bad - except for when receiving large downloads/data sets from a request
  • No optimizations for large amounts of data sent/received (there may be a lot of request/response data that gets processed completely in memory currently)
  • Secure connections require TLS 1.2 according to the RFC so they won't work on Mono at this point
  • No ALPN support (see below)
  • Stream prioritization isn't implemented (you can still send Priority frames)
  • Push Promise isn't implemented, but you can tell the server it is disabled
  • Much more test coverage needed
  • No Upgrade support (only starting with prior knowledge in clear text)
  • HttpClient Support (Http2MessageHandler)
    • Passes along all headers - might not make sense always

Reason for the Lack of ALPN Support

The HTTP/2 RFC states that secure connections must use ALPN to negotiate the protocol. Unfortunately, .NET's SslStream has no ability to specify application protocols as part of the TLS authentication, so it can't support ALPN. There's an issue tracking this on dotnetfx however it seems like this isn't going to happen very soon (especially on mono and .NET 4.x).

In practice, Apple does not enforce this ALPN negotiation on their APNS HTTP/2 servers, and given that they seem to use Netty, it's possible other servers will not require this either.

Not much I can do about this currently.

Using the Http2Client

There's a Http2Client class that can be used to send requests and receive responses:

// Uri to request
var uri = new Uri ("http://somesite.com:80/index.html");

// Create a Http2Client
var http2 = new Http2Client (uri);

// Specify any custom headers
var headers = new NameValueCollection ();
headers.Add ("some-header", "value");

// For some requests you may have a request body
byte[] data = null; 

// Await our response
var response = await http2.Send (uri, HttpMethod.Get, headers, data); 

// Response object has properties:
//  HttpStatusCode Status
//  HttpStream Stream (contains Frames history)
//  NameValueCollection Headers
//  byte[] Body
// ...

Using the HttpClient API

For some familiarity I've implemented a simple HttpMessageHandler so that you can use the HttpClient API:

// Create our HttpTwo handler
var handler = new Http2MessageHandler ();
// Pass the handler into the HttpClient
var http = new HttpClient (handler);

var data = await http.GetStringAsync ("http://somesite.com:80/index.html");

Running Tests

There aren't very many tests right now, however all the tests require a local node-http2 server to be setup to run them. To make this easier, the source is included in HttpTwo.Tests/node-http2. Make sure you run npm install in that folder after check out before you start the NUnit tests (which will automatically launch the node server when you run the tests, and stop it when the tests have completed).

License

Copyright 2015-2016 Jonathan Dick

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

HPack Code

This library uses HPACK code which is licensed under Apache 2.0 and was borrowed from Ringo Leese's repository at: https://github.com/ringostarr80/hpack

Thanks @ringostarr80 !




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
hibri/HttpMock: A library for creating Http servers on the fly in tests and stub ...发布时间:2022-06-18
下一篇:
torch/torch7: http://torch.ch发布时间:2022-06-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap