Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for CURLMOPT_PUSHFUNCTION and CURLMOPT_PUSHDATA (http2 push functionality) #232

Closed
MoMannn opened this issue Jun 20, 2020 · 6 comments
Assignees
Milestone

Comments

@MoMannn
Copy link

MoMannn commented Jun 20, 2020

Bindings for above functionalities are not yet supported which are integral to a http2 client.

@JCMais JCMais self-assigned this Jun 21, 2020
@JCMais JCMais added the feature label Jun 21, 2020
@JCMais JCMais modified the milestones: v2.1.3, v2.1.4, 2.2.0 Jun 21, 2020
@JCMais
Copy link
Owner

JCMais commented Jun 23, 2020

I should be able to add some basic support for this feature in the following days.

The plan is to make it available in a pre-release version for v2.2.0, so it can be tested before being released.

JCMais added a commit that referenced this issue Jun 26, 2020
this option allows to handle http2 server pushes - See #232
@JCMais
Copy link
Owner

JCMais commented Jun 26, 2020

@MoMannn I've just added support for CURLMOPT_PUSHFUNCTION, sample code can be found at ./examples/20-http2-server-push.js.

To use it install the pre-release version v2.2.0-1, you can do that with yarn add node-libcurl@next.

For more documentation see the overloaded method documentation temporarily available here: https://jovial-kilby-4334c9.netlify.app/classes/_multi_.multi.html#setopt

Also, I've created a Discord server: https://discord.gg/3vacxRY

Feel free to join to discuss any issues / give feedback related to the implementation.

Sample output from running the above code on my machine:

Version: libcurl/7.69.1-DEV OpenSSL/1.1.1d zlib/1.2.11 WinIDN libssh2/1.9.0_DEV nghttp2/1.40.0
Protocols: dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Features: AsynchDNS, IDN, IPv6, Largefile, SSPI, Kerberos, SPNEGO, NTLM, SSL, libz, HTTP2, HTTPS-proxy
*   Trying 130.211.116.44:443...
* Connected to http2.golang.org (130.211.116.44) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=http2.golang.org
*  start date: Jun 13 04:42:36 2020 GMT
*  expire date: Sep 11 04:42:36 2020 GMT
*  subjectAltName: host "http2.golang.org" matched cert's "http2.golang.org"
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x22504533fb0)
> GET /serverpush HTTP/2
Host: http2.golang.org
accept: */*

* Connection state changed (MAX_CONCURRENT_STREAMS == 250)!
-> received push frame with 4 headers
|-> header 0 value is: :method:GET
|-> header 1 value is: :scheme:https
|-> header 2 value is: :authority:http2.golang.org
|-> header 3 value is: :path:/serverpush/static/playground.js?1593208678452683550
|-> :scheme header value is: "https"
|-> :authority header value is: "http2.golang.org"
|-> :path header value is: "/serverpush/static/playground.js?1593208678452683550"
||-> push allowed as it is a known file
||-> adding callback to write file to disk
-> received push frame with 4 headers
|-> header 0 value is: :method:GET
|-> header 1 value is: :scheme:https
|-> header 2 value is: :authority:http2.golang.org
|-> header 3 value is: :path:/serverpush/static/style.css?1593208678452683550
|-> :scheme header value is: "https"
|-> :authority header value is: "http2.golang.org"
|-> :path header value is: "/serverpush/static/style.css?1593208678452683550"
||-> unknown file - denying push
-> received push frame with 4 headers
|-> header 0 value is: :method:GET
|-> header 1 value is: :scheme:https
|-> header 2 value is: :authority:http2.golang.org
|-> header 3 value is: :path:/serverpush/static/jquery.min.js?1593208678452683550
|-> :scheme header value is: "https"
|-> :authority header value is: "http2.golang.org"
|-> :path header value is: "/serverpush/static/jquery.min.js?1593208678452683550"
||-> unknown file - denying push
-> received push frame with 4 headers
|-> header 0 value is: :method:GET
|-> header 1 value is: :scheme:https
|-> header 2 value is: :authority:http2.golang.org
|-> header 3 value is: :path:/serverpush/static/godocs.js?1593208678452683550
|-> :scheme header value is: "https"
|-> :authority header value is: "http2.golang.org"
|-> :path header value is: "/serverpush/static/godocs.js?1593208678452683550"
||-> unknown file - denying push
< HTTP/2 200 
< accept-ranges: bytes
< content-type: application/javascript
< last-modified: Wed, 01 Apr 2020 16:33:23 GMT
< content-length: 14585
< date: Fri, 26 Jun 2020 21:57:58 GMT
<
Handle for https://http2.golang.org/serverpush/static/playground.js?1593208678452683550 () finished with response code 200
undefined
< HTTP/2 200 
< content-type: text/html; charset=utf-8
< date: Fri, 26 Jun 2020 21:57:58 GMT
<
Handle for https://http2.golang.org/serverpush () finished with response code 200
[
  <Buffer 0a 0a 3c 21 44 4f 43 54 59 50 45 20 68 74 6d 6c 3e 0a 3c 68 74 6d 6c 3e 0a 3c 68 65 61 64 3e 0a 3c 6d 65 74 61 20 68 74 74 70 2d 65 71 75 69 76 3d 22 ... 4006 more bytes>,
  <Buffer 20 20 20 20 64 65 73 63 72 69 70 74 69 6f 6e 20 6f 66 20 74 65 73 74 69 6e 67 20 66 75 6e 63 74 69 6f 6e 73 0a 3c 2f 70>,
  <Buffer 72 65 3e 0a 3c 70 3e 0a 55 73 65 20 26 23 33 34 3b 67 6f 20 68 65 6c 70 20 5b 74 6f 70 69 63 5d 26 23 33 34 3b 20 66 6f 72 20 6d 6f 72 65 20 69 6e 66 ... 16325 more bytes>,
  <Buffer 20 73 65 65 20 26 23 33 39>,
  <Buffer 3b 67 6f 20 68 65 6c 70 20 62 75 69 6c 64 26 23 33 39 3b 2e 0a 3c 2f 70 3e 0a 3c 70 3e 0a 46 6f 72 20 6d 6f 72 65 20 61 62 6f 75 74 20 73 70 65 63 69 ... 16325 more bytes>,
  <Buffer 6c 65 73 0a 69 6e 20 65 61>,
  <Buffer 63 68 20 64 69 72 65 63 74 6f 72 79 2e 20 49 74 20 69 64 65 6e 74 69 66 69 65 73 20 77 68 69 63 68 20 66 69 6c 65 73 20 74 6f 20 65 78 61 6d 69 6e 65 ... 16325 more bytes>,
  <Buffer 20 61 20 63 6f 6d 6d 65 6e>,
  <Buffer 74 20 6f 66 20 6f 6e 65 20 6f 66 20 74 68 65 73 65 20 74 77 6f 20 66 6f 72 6d 73 3a 0a 3c 2f 70 3e 0a 3c 70 72 65 3e 70 61 63 6b 61 67 65 20 6d 61 74 ... 13924 more bytes>,
  <Buffer 31 35 39 33 32 30 38 36 37 38 34 35 32 36 38 33 35 35 30 22 3e 3c 2f 73 63 72 69 70 74 3e 0a 3c 73 63 72 69 70 74 20 74 79 70 65 3d 22 74 65 78 74 2f ..]

@JCMais
Copy link
Owner

JCMais commented Jun 29, 2020

@JCMais
Copy link
Owner

JCMais commented Jul 13, 2020

@MoMannn in case you have tried the feature, did it work as you expected?

Planning on releasing v2.2 tomorrow.

@MoMannn
Copy link
Author

MoMannn commented Jul 14, 2020

Not yet, will start working on it today.

@JCMais
Copy link
Owner

JCMais commented Jul 14, 2020

@MoMannn I've released v2.2.0, if you find any issues with this option feel free to create an issue. 👍

@JCMais JCMais closed this as completed Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants