Search code examples
vue.jsaxioskeep-alive

Is there a way to remove connection: keep-alive from axios?


Axios is assigned to Vue.prototype which is directly imported from node_modules like:

import axios from "axios";
import Vue from "vue"

Vue.prototype.axios = axios;

Every time the browser sends a request, connection: keep-alive is available.

Is there a way to remove the header?

The default header availabe in axios.defaults.headers.common is

{
    Accept: "application/json, text/plain, */*
}

Solution

  • If you have a look at the documentation for the Connection-header it is classified as as "Forbidden header name".

    What this basically means is that they are handled by the browser and can't be changed by code.

    This is also true for a bunch of other headers such as Referer and Cookie (the whole list is available at https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name).