001package ca.uhn.hl7v2.hoh.encoder; 002 003import ca.uhn.hl7v2.hoh.util.VersionLogger; 004 005public class Hl7OverHttpResponseEncoder extends AbstractHl7OverHttpEncoder { 006 007 private boolean myAddConnectionCloseHeader; 008 009 @Override 010 protected void addSpecificHeaders() { 011 getHeaders().put("Server", "HAPI (HL7 over HTTP) Server " + VersionLogger.getVersion()); 012 if (isGzipData()) { 013 getHeaders().put("Content-Encoding", "gzip"); 014 } 015 if (myAddConnectionCloseHeader) { 016 getHeaders().put("Connection", "close"); 017 } 018 } 019 020 @Override 021 protected void setActionLineAppropriately() { 022 ResponseCode resp = ResponseCode.detect(getMessage()); 023 setActionLine("HTTP/1.1 " + resp.getCode() + " " + resp.getMessage()); 024 } 025 026 /** 027 * Adds a header to the HTTP response: "<code>Connection: close</code>". Note that setting this to true (default is false) will ONLY add the header, it does not actually close the connection. The 028 * caller is responsible for that. 029 */ 030 public void setAddConnectionCloseHeader(boolean theAddConnectionCloseHeader) { 031 myAddConnectionCloseHeader = theAddConnectionCloseHeader; 032 } 033 034 /** 035 * Should response be GZipped? 036 */ 037 @Override 038 public void setGzipData(boolean theGzipData) { 039 super.setGzipData(theGzipData); 040 } 041 042}