Changeset 1095
- Timestamp:
- 06/19/08 15:06:43 (3 months ago)
- Files:
-
- trunk/mango/net/http/server/HttpBridge.d (modified) (1 diff)
- trunk/mango/net/http/server/HttpMessage.d (modified) (1 diff)
- trunk/mango/net/http/server/HttpResponse.d (modified) (4 diffs)
- trunk/mango/net/http/server/HttpServer.d (modified) (3 diffs)
- trunk/mango/net/servlet/ServletProvider.d (modified) (2 diffs)
- trunk/mango/net/servlet/ServletResponse.d (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/mango/net/http/server/HttpBridge.d
r1092 r1095 93 93 94 94 // close and destroy this conduit (socket) 95 //scope (exit) 96 //conduit.detach; 95 scope (exit) 96 if (! response.managedConnection) 97 conduit.detach; 97 98 98 // reset the (probably overridden) input and output 99 request.reset(); 100 response.reset(); 99 do { 100 // reset the (probably overridden) input and output 101 request.reset; 102 response.reset; 101 103 102 // first, extract HTTP headers from input103 request.readHeaders ();104 // first, extract HTTP headers from input 105 request.readHeaders; 104 106 105 // pass request off to the provider. It is the provider's 106 // responsibility to flush the output! 107 provider.service (request, response); 107 // pass request off to the provider. It is the provider's 108 // responsibility to flush the output! 109 provider.service (request, response); 110 } while (response.keepAlive); 108 111 } 109 112 } trunk/mango/net/http/server/HttpMessage.d
r1083 r1095 105 105 encoding = null; 106 106 mimeType = null; 107 headers.reset(); 107 headers.reset; 108 109 // make some space in the buffer, perhaps for keepalive 110 buffer.compress; 108 111 } 109 112 trunk/mango/net/http/server/HttpResponse.d
r1059 r1095 52 52 private IBuffer output; 53 53 private bool commited; 54 private bool keepalive; 55 private bool isManaged; 54 56 55 57 static private InvalidStateException InvalidState; … … 110 112 // reset output parameters 111 113 params.reset; 114 115 // reset these too 116 keepalive = false; 117 isManaged = false; 112 118 } 113 119 … … 266 272 /********************************************************************** 267 273 274 set the keepalive flag for this response, which will add 275 a header also. An exception is thrown if we're already in 276 a committed state 277 278 **********************************************************************/ 279 280 final void keepAlive (bool yes) 281 { 282 if (commited) 283 throw InvalidState; 284 keepalive = yes; 285 } 286 287 /********************************************************************** 288 289 Return the keepalive flag for this response 290 291 **********************************************************************/ 292 293 final bool keepAlive () 294 { 295 return keepalive; 296 } 297 298 /********************************************************************** 299 300 Set internal flag to leave the connected socket open. Use 301 with extreme care 302 303 **********************************************************************/ 304 305 final void managedConnection (bool yes) 306 { 307 isManaged = yes; 308 } 309 310 /********************************************************************** 311 312 Return whether to leave the connected socket open. See 313 above 314 315 **********************************************************************/ 316 317 final bool managedConnection () 318 { 319 return isManaged; 320 } 321 322 /********************************************************************** 323 268 324 Private method to send the response status, and the 269 325 output headers, back to the user-agent … … 295 351 (HttpConst.Eol); 296 352 297 // tell client we don't support keep-alive353 // set connection header 298 354 if (! headers.get (HttpHeader.Connection)) 299 headers.add (HttpHeader.Connection, "close");355 headers.add (HttpHeader.Connection, keepalive ? "keep-alive" : "close"); 300 356 301 357 // write the header tokens, followed by a blank line 302 358 super.produce (&emit.consume, HttpConst.Eol); 303 304 emit(HttpConst.Eol); 359 emit (HttpConst.Eol); 305 360 306 361 version (ShowHeaders) trunk/mango/net/http/server/HttpServer.d
r1092 r1095 40 40 { 41 41 private ServiceProvider provider; 42 private bool close = true;43 42 44 43 /********************************************************************** … … 84 83 { 85 84 return "http"; 86 }87 88 /**********************************************************************89 90 Configure whether each connection is detached after being91 serviced. The default behaviour is to close the connection92 93 **********************************************************************/94 95 void detach (bool yes)96 {97 this.close = yes;98 85 } 99 86 … … 151 138 ServiceBridge bridge; 152 139 153 scope (exit)154 if (close)155 conduit.detach;156 157 140 // we know what this is because we created it (above) 158 141 thread = cast(HttpThread) st; trunk/mango/net/servlet/ServletProvider.d
r1094 r1095 333 333 334 334 // retrieve the requested uri 335 path = request.uri.getPath(); 336 log.info ("request path '{}'", path); 335 path = request.uri.getPath; 336 337 // log the request 338 if (log.enabled (log.Trace)) 339 log.trace ("request for path '{}' from uri '{}'", path, request.uri); 337 340 338 341 // lookup servlet for this path 339 pm = cast (PathMapping) cache.get (path);342 pm = cast(PathMapping) cache.get (path); 340 343 341 344 // construct a new cache entry if not found … … 354 357 } 355 358 356 // ready to go ...357 359 try { 358 // initialize the servlet environment 359 request.set (pm.mapping.proxy.getName, pm.mapping.proxy.getContext); 360 // ready to go ... 361 auto proxy = pm.mapping.proxy; 362 363 // initialize servlet environment 364 request.set (proxy.getName, proxy.getContext); 360 365 361 366 // execute servlet 362 p m.mapping.proxy.getServlet.service (request, response);367 proxy.getServlet.service (request, response); 363 368 364 369 // flush output on behalf of servlet ... trunk/mango/net/servlet/ServletResponse.d
r1087 r1095 18 18 tango.io.FileConduit; 19 19 20 private import Path = tango.io.Path; 21 20 22 private import tango.io.model.IBuffer; 21 23 … … 34 36 /****************************************************************************** 35 37 38 Note that an instance of this is maintained by the server on a 39 per-thread basis. 40 36 41 ******************************************************************************/ 37 42 38 43 class ServletResponse : HttpResponse, IServletResponse 39 44 { 45 // we retain one of these to avoid creation costs 46 private FileConduit file; 47 40 48 /********************************************************************** 41 49 … … 184 192 bool copyFile (IServletContext context, char[] path) 185 193 { 186 FileConduit source; 194 // does the file exist? 195 if (file is null) 196 file = new FileConduit; 187 197 188 198 try { 189 // does the file exist? 190 source = new FileConduit (context.getResourceAsPath (path)); 199 file.open (context.getResourceAsPath (path)); 191 200 192 201 // set expected output size 193 setContentLength (cast(int) source.length);202 setContentLength (cast(int) file.length); 194 203 195 204 // set content-type if not already set 196 205 if (getContentType is null) 197 206 { 198 char[] mime = context.getMimeType (source.path.suffix); 207 auto p = Path.parse (path); 208 char[] mime = context.getMimeType (p.suffix); 199 209 if (mime is null) 200 210 mime = "text/plain"; … … 204 214 205 215 // copy file to output 206 buffer.copy ( source);216 buffer.copy (file); 207 217 return true; 208 218 … … 213 223 finally 214 224 { 215 if (source) 216 source.detach; 225 file.detach; 217 226 } 218 227 return false; 219 228 } 220 229 } 221 222
