public OutputStream getOutputStream() throws IOException {
		if (output==null) {
			throw new IOException("headers already sent");
		}
		final Charset ascii = StandardCharsets.US_ASCII;
		final byte[] separ = ": ".getBytes(ascii);
		final byte[] comma = ", ".getBytes(ascii);
		final byte[] endl = "\n".getBytes(ascii);
		
		final OutputStream out = this.output;
		this.output = null;
		
		final boolean gzip = this.autoGzip && this.headers.getValue("Content-Encoding")==null;
		if (gzip) {
			this.headers.setValue("Content-Encoding", "gzip");
		}
		out.write("HTTP/1.1 ".getBytes(ascii));
		out.write((this.status + " " + this.statusMessage).getBytes(ascii));
		out.write(endl);
		
		for (Map.Entry<String, String[]> header : this.headers.values()) {
			out.write(header.getKey().getBytes(ascii));
			out.write(separ);
			boolean first = true;
			
			for (String value : header.getValue()) {
				if (first) {
					first = false;
				} else {
					out.write(comma);
				}
				out.write(value.getBytes(ascii));
			}
			out.write(endl);
		}
		out.write(endl);
		out.flush();
		
		if (gzip) {
			return new GZIPOutputStream(out);
		}
		return out;
	}