01: package vicazh.hyperpool.stream.net.http;
02:
03: import java.io.*;
04: import java.util.*;
05: import vicazh.hyperpool.stream.*;
06: import vicazh.hyperpool.stream.net.Stream;
07: import vicazh.hyperpool.stream.Selector;
08:
09: class RefererStream extends ClientStream {
10:
11: RefererStream(Session session, OutputStream outputstream) {
12: super (session, new NullStream(outputstream));
13: }
14:
15: private boolean b;
16:
17: public void field(String s1, String s2) throws IOException {
18: if (s1.equalsIgnoreCase("Referer"))
19: b = true;
20: super .field(s1, s2);
21: }
22:
23: public void header() throws IOException {
24: if (((NullStream) outputstream).outputstream == null
25: || ((RefererConnection) connection).b != b) {
26: if (((NullStream) outputstream).outputstream != null) {
27: synchronized (connection) {
28: if (((Connection) connection).getSessions().size() > 1)
29: try {
30: connection.wait();
31: } catch (InterruptedException e) {
32: }
33: }
34: connection.getServer().outputstream = null;
35: connection.setServer(new Stream(
36: (Connection) connection, session.getServer()));
37: outputstream.flush();
38: outputstream.close();
39: }
40: ((RefererConnection) connection).b = b;
41: outputstream = ((Selector) connection.element).get(
42: connection.getServer(),
43: b ? ((RefererSelector) connection.element).getRef()
44: : ((Selector) connection.element).getDef());
45: }
46: head(getMethod(), getFile(), getVersion());
47: for (Map.Entry<String, String> e : getFields().entrySet())
48: super.field(e.getKey(), e.getValue());
49: super.header();
50: }
51: }
|