Axios expose response headers: Content-Disposition

In my case I had to enable CORS-related feature on the server side: Access-Control-Expose-Headers: Content-Disposition This allows javascript on the browser side to read this header. In case of node.js + express + cors on the server side it may looks like this: app.use(cors({ origin: ‘http://localhost:8080’, credentials: true, exposedHeaders: [‘Content-Disposition’] })) So I can see … Read more

How do delete a HTTP response header?

You can’t delete headers afterwards by the standard Servlet API. Your best bet is to just prevent the header from being set. You can do this by creating a Filter which replaces the ServletResponse with a custom HttpServletResponseWrapper implementation which skips the setHeader()‘s job whenever the header name is Content-Disposition. Basically: @Override public void doFilter(ServletRequest … Read more

automatically add header to every response

I recently got into this issue and found this solution. You can use a filter to add these headers : import java.io.IOException; import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.filter.OncePerRequestFilter; public class CorsFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { response.addHeader(“Access-Control-Allow-Origin”, “*”); if (request.getHeader(“Access-Control-Request-Method”) … Read more

Is header(‘Content-Type:text/plain’); necessary at all?

Define “necessary”. It is necessary if you want the browser to know what the type of the file is. PHP automatically sets the Content-Type header to text/html if you don’t override it so your browser is treating it as an HTML file that doesn’t contain any HTML. If your output contained any HTML you’d see … Read more

Express.js – How to check if headers have already been sent?

Node supports the res.headersSent these days, so you could/should use that. It is a read-only boolean indicating whether the headers have already been sent. if(res.headersSent) { … } See http://nodejs.org/api/http.html#http_response_headerssent Note: this is the preferred way of doing it, compared to the older Connect ‘headerSent’ property that Niko mentions.

tech