Settings http headers in Java 6 SE httpserver

http-headers, httpserver, java, rss

Solution

You can set the response headers like this:

Headers headers = exchange.getResponseHeaders();
headers.add("Content-Type", "application/atom+xml");
exchange.sendResponseHeaders(200, 0);

Problem

I try to publish Atom feed (generated with Rome) using Java 6 SE httpserver. For correct feed discovery in FireFox I need custom headers. This is my code: ``` Headers headers=e.getRequestHeaders(); ArrayList<String>list=new ArrayList<String>(); list.add("application/atom+xml"); headers.put("content-type", list); e.sendResponseHeaders(200, 0); ``` Unfortunately feed is displaying like xml (browser doesn't, ask me what to do with feed) and sniffing with livehttpheaders shows that there isn't content-type attribute.

Original source