Settings http headers in Java 6 SE httpserver
Asked Answered
L

1

7

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.

Lafollette answered 1/12, 2009 at 19:31 Comment(2)
(I can't remember the code off hand, but it looks like you are adding to the request instead of response headers.)Firstclass
Tom's comment should be an answer. Adding content-type to headers object obtained using getRequestHeaders() is not going to affect what headers are sent in response.Prepositor
C
17

You can set the response headers like this:

Headers headers = exchange.getResponseHeaders();
headers.add("Content-Type", "application/atom+xml");
exchange.sendResponseHeaders(200, 0);
Czarra answered 30/9, 2010 at 10:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.