1 module hunt.http.codec.websocket.model.UpgradeResponseAdapter;
2 
3 
4 import hunt.http.codec.websocket.utils.HeaderValueGenerator;
5 
6 // class UpgradeResponseAdapter : UpgradeResponse {
7 
8 //     static final string SEC_WEBSOCKET_PROTOCOL = WebSocketConstants.SEC_WEBSOCKET_PROTOCOL;
9 
10 //     private int statusCode;
11 //     private string statusReason;
12 //     private Map<string, List<string>> headers = new TreeMap<>(string.CASE_INSENSITIVE_ORDER);
13 //     private List<ExtensionConfig> extensions = new ArrayList<>();
14 //     private bool success = false;
15 
16 //     override
17 //     void addHeader(string name, string value) {
18 //         string key = name;
19 //         List<string> values = headers.get(key);
20 //         if (values is null) {
21 //             values = new ArrayList<>();
22 //         }
23 //         values.add(value);
24 //         headers.put(key, values);
25 //     }
26 
27 //     /**
28 //      * Get the accepted WebSocket protocol.
29 //      *
30 //      * @return the accepted WebSocket protocol.
31 //      */
32 //     override
33 //     string getAcceptedSubProtocol() {
34 //         return getHeader(SEC_WEBSOCKET_PROTOCOL);
35 //     }
36 
37 //     /**
38 //      * Get the list of extensions that should be used for the websocket.
39 //      *
40 //      * @return the list of negotiated extensions to use.
41 //      */
42 //     override
43 //     List<ExtensionConfig> getExtensions() {
44 //         return extensions;
45 //     }
46 
47 //     override
48 //     string getHeader(string name) {
49 //         List<string> values = getHeaders(name);
50 //         // no value list
51 //         if (values is null) {
52 //             return null;
53 //         }
54 //         int size = values.size();
55 //         // empty value list
56 //         if (size <= 0) {
57 //             return null;
58 //         }
59 //         // simple return
60 //         if (size == 1) {
61 //             return values.get(0);
62 //         }
63 //         return generateHeaderValue(values);
64 //     }
65 
66 //     override
67 //     Set<string> getHeaderNames() {
68 //         return headers.keySet();
69 //     }
70 
71 //     override
72 //     Map<string, List<string>> getHeaders() {
73 //         return headers;
74 //     }
75 
76 //     override
77 //     List<string> getHeaders(string name) {
78 //         return headers.get(name);
79 //     }
80 
81 //     override
82 //     int getStatusCode() {
83 //         return statusCode;
84 //     }
85 
86 //     override
87 //     string getStatusReason() {
88 //         return statusReason;
89 //     }
90 
91 //     override
92 //     bool isSuccess() {
93 //         return success;
94 //     }
95 
96 //     /**
97 //      * Issue a forbidden upgrade response.
98 //      * <p>
99 //      * This means that the websocket endpoint was valid, but the conditions to use a WebSocket resulted in a forbidden
100 //      * access.
101 //      * <p>
102 //      * Use this when the origin or authentication is invalid.
103 //      *
104 //      * @param message the short 1 line detail message about the forbidden response
105 //      * @throws IOException if unable to send the forbidden
106 //      */
107 //     override
108 //     void sendForbidden(string message) throws IOException {
109 //         throw new UnsupportedOperationException("Not supported");
110 //     }
111 
112 //     /**
113 //      * Set the accepted WebSocket Protocol.
114 //      *
115 //      * @param protocol the protocol to list as accepted
116 //      */
117 //     override
118 //     void setAcceptedSubProtocol(string protocol) {
119 //         setHeader(SEC_WEBSOCKET_PROTOCOL, protocol);
120 //     }
121 
122 //     /**
123 //      * Set the list of extensions that are approved for use with this websocket.
124 //      * <p>
125 //      * Notes:
126 //      * <ul>
127 //      * <li>Per the spec you cannot add extensions that have not been seen in the {@link UpgradeRequest}, just remove entries you don't want to use</li>
128 //      * <li>If this is unused, or a null is passed, then the list negotiation will follow default behavior and use the complete list of extensions that are
129 //      * available in this WebSocket server implementation.</li>
130 //      * </ul>
131 //      *
132 //      * @param extensions the list of extensions to use.
133 //      */
134 //     override
135 //     void setExtensions(List<ExtensionConfig> extensions) {
136 //         this.extensions.clear();
137 //         if (extensions !is null) {
138 //             this.extensions.addAll(extensions);
139 //         }
140 //     }
141 
142 //     override
143 //     void setHeader(string name, string value) {
144 //         List<string> values = new ArrayList<>();
145 //         values.add(value);
146 //         headers.put(name, values);
147 //     }
148 
149 //     override
150 //     void setStatusCode(int statusCode) {
151 //         this.statusCode = statusCode;
152 //     }
153 
154 //     override
155 //     void setStatusReason(string statusReason) {
156 //         this.statusReason = statusReason;
157 //     }
158 
159 //     override
160 //     void setSuccess(bool success) {
161 //         this.success = success;
162 //     }
163 // }