1 28 29 package com.caucho.server.http; 30 31 import java.io.*; 32 import java.net.*; 33 import java.util.*; 34 import javax.servlet.*; 35 import javax.servlet.http.*; 36 37 import com.caucho.util.*; 38 import com.caucho.vfs.*; 39 40 import com.caucho.server.connection.AbstractHttpRequest; 41 import com.caucho.server.connection.AbstractHttpResponse; 42 43 47 public class RunnerResponse extends AbstractHttpResponse { 48 RunnerRequest _req; 49 50 RunnerResponse(RunnerRequest request) 51 { 52 super(request); 53 54 _req = request; 55 } 56 57 60 public boolean isTop() 61 { 62 if (! (_request instanceof AbstractHttpRequest)) 63 return false; 64 else { 65 return ((AbstractHttpRequest) _request).isTop(); 66 } 67 } 68 69 protected boolean writeHeadersInt(WriteStream os, int length) 70 throws IOException 71 { 72 CharBuffer cb = _cb; 73 cb.clear(); 74 int version = _req.getVersion(); 75 if (version >= HttpRequest.HTTP_1_1) 76 cb.append("HTTP/1.1 "); 77 else 78 cb.append("HTTP/1.0 "); 79 cb.append((char) ((_statusCode / 100) % 10 + '0')); 80 cb.append((char) ((_statusCode / 10) % 10 + '0')); 81 cb.append((char) (_statusCode % 10 + '0')); 82 cb.append(' '); 83 cb.append(_statusMessage); 84 85 _req.writeStatus(cb); 86 87 if (_statusCode >= 400) { 88 removeHeader("ETag"); 89 removeHeader("Last-Modified"); 90 } 91 else if (_isNoCache) { 92 removeHeader("ETag"); 93 removeHeader("Last-Modified"); 94 95 setHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT"); 96 _req.writeHeader("Cache-Control", "no-cache"); 97 } 98 else if (isPrivateCache()) 99 _req.writeHeader("Cache-Control", "private"); 100 101 for (int i = 0; i < _headerKeys.size(); i++) { 102 String key = (String) _headerKeys.get(i); 103 String value = (String) _headerValues.get(i); 104 105 _req.writeHeader(key, value); 106 } 107 108 if (_contentLength >= 0) { 109 cb.clear(); 110 cb.append(_contentLength); 111 _req.writeHeader("Content-Length", cb); 112 } 113 else if (length >= 0) { 114 cb.clear(); 115 cb.append(length); 116 _req.writeHeader("Content-Length", cb); 117 } 118 119 long now = Alarm.getCurrentTime(); 120 for (int i = 0; i < _cookiesOut.size(); i++) { 121 Cookie cookie = (Cookie) _cookiesOut.get(i); 122 int cookieVersion = cookie.getVersion(); 123 124 fillCookie(cb, cookie, now, 0); 125 _req.writeHeader("Set-Cookie", cb); 126 if (cookieVersion > 0) { 127 fillCookie(cb, cookie, now, cookieVersion); 128 _req.writeHeader("Set-Cookie2", cb); 129 } 130 } 131 132 if (_contentType != null) 133 _req.writeHeader("Content-Type", _contentType); 134 135 _req.sendHeader(); 136 137 return false; 138 } 139 } 140 | Popular Tags |