Mercurial Hosting > luan
comparison src/luan/webserver/Response.java @ 1137:c123ee15f99b
add webserver
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 29 Jan 2018 18:49:59 -0700 |
parents | |
children | 2dda3c92a473 |
comparison
equal
deleted
inserted
replaced
1136:d30d400fd43d | 1137:c123ee15f99b |
---|---|
1 package luan.webserver; | |
2 | |
3 import java.io.InputStream; | |
4 import java.util.Map; | |
5 import java.util.LinkedHashMap; | |
6 import java.util.Collections; | |
7 | |
8 | |
9 public class Response { | |
10 public final String protocol = "HTTP/1.1"; | |
11 public volatile Status status = Status.OK; | |
12 public final Map<String,String> headers = Collections.synchronizedMap(new LinkedHashMap<String,String>()); | |
13 { | |
14 headers.put("Server","ThreeBody"); | |
15 } | |
16 public volatile Body body; | |
17 | |
18 public static class Body { | |
19 public final long length; | |
20 public final InputStream content; | |
21 | |
22 public Body(long length,InputStream content) { | |
23 this.length = length; | |
24 this.content = content; | |
25 } | |
26 } | |
27 | |
28 | |
29 public String toHeaderString() { | |
30 StringBuilder sb = new StringBuilder(); | |
31 sb.append( protocol ) | |
32 .append( ' ' ).append( status.code ) | |
33 .append( ' ' ).append( status.reason ) | |
34 .append( "\r\n" ) | |
35 ; | |
36 for( Map.Entry<String,String> entry : headers.entrySet() ) { | |
37 String name = entry.getKey(); | |
38 String value = entry.getValue(); | |
39 sb.append( name ).append( ": " ).append( value ).append( "\r\n" ); | |
40 } | |
41 sb.append( "\r\n" ); | |
42 return sb.toString(); | |
43 } | |
44 } |