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

HTTP/2 support #1175

Open
InterAl opened this issue Nov 9, 2017 · 75 comments
Open

HTTP/2 support #1175

InterAl opened this issue Nov 9, 2017 · 75 comments
Projects

Comments

@InterAl
Copy link

InterAl commented Nov 9, 2017

Is there any plan to add HTTP/2 support for node.js? Since it is now officially supported in node.js 9, I think it's highly desirable to have this library support it as well.

@IshamMohamed
Copy link

I would like to see this functionality.

@maxim25
Copy link

maxim25 commented Dec 28, 2017

+1

4 similar comments
@vgraveto
Copy link

+1

@nidrax69
Copy link

+1

@redfish31
Copy link

+1

@lyonish
Copy link

lyonish commented Feb 2, 2018

+1

@Khaledgarbaya
Copy link
Collaborator

Please use the emoji to vote, adding +1 comment won't help

@axios axios locked as spam and limited conversation to collaborators Feb 6, 2018
@axios axios unlocked this conversation Feb 6, 2018
@konstantinsteinmiller
Copy link

👍

3 similar comments
@mashintsev
Copy link

👍

@AshishKirodian
Copy link

+1

@yumaojun03
Copy link

+1

@MykhailoMatiiasevych
Copy link

Since Node 10 is LTS and it has Stable HTTP/2 support I would like to have this functionality in axios

@qraynaud
Copy link

qraynaud commented Dec 5, 2018

Looking at the actual code in axios, seems like a headache. Wouldn't it be easier to just pass in another transport that would be a wrapper for the http API over the htt2 API? You could write such a code more easily I think!

Relevant code is here: https://github.com/axios/axios/blob/master/lib/adapters/http.js#L180

@qraynaud
Copy link

qraynaud commented Dec 5, 2018

Should also be possible to write a simple adapter for this (look adapter in the documentation).

@range-of-motion
Copy link

So what's up with this? Are we fucked if we wanna use HTTP/2 with Axios? It's been a year, has anyone found a solution to this?

@snowdream
Copy link

Any Update?

@Y0geshsharma
Copy link

Hello guys,
i faced an issue while using post for a file object.
"code snippet"
Axios
.post(url,fileobject)
.then()
.catch(error=>{
console.log(error)
})
"

@jasonsaayman
Copy link
Member

yeah my mission over the next while will be to try make the contribution much easier

@oleksiukmarydev
Copy link

oleksiukmarydev commented Jul 4, 2023

I custom the transport by http2-wrapper module for support HTTP/2.

const http2 = require("http2-wrapper");
const axios = require("axios");

const http2Transport = {
  request: function request(options, handleResponse) {
    const req = http2.request(options, handleResponse);
    setImmediate(() => {
      // Remove the axios action `socket.setKeepAlive` because the HTTP/2 sockets should not be directly manipulated
      const listeners = req.listeners("socket");
      if (listeners.length) req.removeListener("socket", listeners[0]);
    });
    return req;
  },
};

axios
  .get("https://httpbin.org/", {
    transport: http2Transport,
  })
  .then((res) => {
    console.log(res.data);
  });

adapter version

function http2AdapterEnhancer(adapter) {
  return async (config) => {
    if (config.http2) {
      let req;
      config.transport = {
        request: function request(options, handleResponse) {
          req = http2.request(options, handleResponse);
          return req;
        },
      };
      const ret = adapter(config);
      // Remove the axios action `socket.setKeepAlive` because the HTTP/2 sockets should not be directly manipulated
      const listeners = req.listeners("socket");
      if (listeners.length) req.removeListener("socket", listeners[0]);
      return ret;
    } else {
      return adapter(config);
    }
  };
}

const http2Adapter = http2AdapterEnhancer(axios.defaults.adapter);

axios
  .get("https://httpbin.org/", {
    http2: true,
    adapter: http2Adapter,
  })
  .then((res) => {
    console.log(res.data);
  });

How do i use the transport? Is it still a working solution @arronzhang because i can't find any documentation on that.
I've tried to create axios.js file as following but there are error that https and ./framer cant be found.

const  http2 = require('http2-wrapper');
const axios = require('axios');
const http2Transport = {
  request: function request(options, handleResponse) {
    const req = http2.request(options, handleResponse);
    setImmediate(() => {
      // Remove the axios action `socket.setKeepAlive` because the HTTP/2 sockets should not be directly manipulated
      const listeners = req.listeners('socket');
      if (listeners.length) req.removeListener('socket', listeners[0]);
    });
    return req;
  },
};
const instance = axios.create();
instance.defaults.transport = http2Transport;
export default instance;

Should i add http2 transport separately from axios config somewhere?

@nestle49
Copy link

nestle49 commented Jul 7, 2023

Still waiting http2

@DaniilIsupov
Copy link

I'm waiting for HTTP/2. But I don't want to do PR

@nestle49
Copy link

Maybe I can donate to someone who can add http2 support?

@swcm-mnestler
Copy link

Looks like the work on HTTP/2 in nodejs/undici#2061 is nearing an experimental release, a (native) fetch adapter (#1219, #5146) would get HTTP/2 support "for free". Very interested in this avenue

@simllll
Copy link

simllll commented Jul 28, 2023

Looks like the work on HTTP/2 in nodejs/undici#2061 is nearing an experimental release, a (native) fetch adapter (#1219, #5146) would get HTTP/2 support "for free". Very interested in this avenue

https://www.npmjs.com/package/haxios is something like this, it's using native fetch behind the scene, has http2 support therefore, but imitates the axios interface, so it can be used as a drop in replacement. (disclaimer, haxios was invented by myself some time ago, but we are not using axios in any way anymore)

@nestle49
Copy link

nestle49 commented Sep 1, 2023

any news?

@nestle49
Copy link

nestle49 commented Oct 6, 2023

any updates?

@DaniilIsupov
Copy link

i would like to see HTTP/2 support already

@nestle49
Copy link

axios doesn't support http2 yet! :mad: :mad: 😠 😠 😡

@einSelbst
Copy link

guys, so many alternatives, haxios was mentioned, here is even more https://github.com/sindresorhus/got#comparison

@nestle49
Copy link

guys, so many alternatives, haxios was mentioned

This package has been deprecated

R u serious?

@nestle49
Copy link

galaxy far, far away...

@DaniilIsupov
Copy link

is there any news?

@nestle49
Copy link

axios is dead

@alexandr-gerasimovich
Copy link

when will http2 support be available? it's no longer possible to live like this

@DaniilIsupov
Copy link

apparently axios is deprecated
i will migrate our entire ecosystem to got (there was support already in 2021)

@Tibing
Copy link

Tibing commented Dec 20, 2023

I've managed to build the http2 adapter available as an npm package, check it out here: https://github.com/uibakery/axios-http2-adapter

@nestle49
Copy link

nestle49 commented Feb 5, 2024

@jasonsaayman Perhaps you could help at least decompose the problem or create a roadmap?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v1.0.0
  
To do
Development

No branches or pull requests