Added a few more changes into the mix. Only changes left are in WebServer.
This commit is contained in:
@@ -162,7 +162,7 @@ public class Request implements IRequest {
|
||||
* @return The field value for the given field name, or null if the key is not used.
|
||||
*/
|
||||
public String getHeaderFieldValue(String fieldName) {
|
||||
return (String) headerFieldMap.get(fieldName);
|
||||
return (String) headerFieldMap.get(fieldName.toLowerCase());
|
||||
}//getHeaderFieldValue()//
|
||||
/**
|
||||
* Processes the header for the request.
|
||||
@@ -1324,7 +1324,7 @@ public String[] getHeaderFieldNames() {
|
||||
* @see com.foundation.web.interfaces.IRequest#getHeaderFieldValue(java.lang.String)
|
||||
*/
|
||||
public String getHeaderFieldValue(String fieldName) {
|
||||
return getHeaderFieldValue(fieldName);
|
||||
return header.getHeaderFieldValue(fieldName);
|
||||
}//getHeaderFieldValue()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.web.IRequest#getContentType()
|
||||
|
||||
@@ -13,8 +13,10 @@ import java.util.Date;
|
||||
|
||||
import com.common.debug.Debug;
|
||||
import com.common.io.StreamSupport;
|
||||
import com.common.security.Sha1;
|
||||
import com.common.util.LiteHashMap;
|
||||
import com.common.util.LiteList;
|
||||
import com.common.util.StringSupport;
|
||||
import com.foundation.event.IRequestHandler;
|
||||
import com.foundation.web.interfaces.*;
|
||||
|
||||
@@ -131,6 +133,37 @@ public void setError(int errorType) {
|
||||
throw new RuntimeException("Cannot set the response content twice.");
|
||||
}//else//
|
||||
}//setError()//
|
||||
/**
|
||||
* Called to accept a web socket upgrade attempt.
|
||||
* @param key The key passed by the client in the websocket upgrade call.
|
||||
* @param protocol The optional protocol selected by the server, or null if no protocol option is necessary.
|
||||
*/
|
||||
public void acceptWebSocketUpgrade(String key, String protocol) {
|
||||
if(this.content == null) {
|
||||
String acceptCode = StringSupport.base64Encode(new Sha1().hash(key.concat("258EAFA5-E914-47DA-95CA-C5AB0DC85B11")));
|
||||
|
||||
this.headerFieldMap = new LiteHashMap(10);
|
||||
this.headerFieldNames = new LiteList(4, 10);
|
||||
|
||||
this.headerFieldMap.put(null, "HTTP/1.1 101 Switching Protocols");
|
||||
this.headerFieldMap.put("Upgrade", "websocket");
|
||||
this.headerFieldNames.add("Upgrade");
|
||||
this.headerFieldMap.put("Connection", "Upgrade");
|
||||
this.headerFieldNames.add("Connection");
|
||||
this.headerFieldMap.put("Sec-WebSocket-Accept", acceptCode);
|
||||
this.headerFieldNames.add("Sec-WebSocket-Accept");
|
||||
|
||||
if(protocol != null) {
|
||||
this.headerFieldMap.put("Sec-WebSocket-Protocol", protocol);
|
||||
this.headerFieldNames.add("Sec-WebSocket-Protocol");
|
||||
}//if//
|
||||
|
||||
this.content = null;
|
||||
}//if//
|
||||
else {
|
||||
throw new RuntimeException("Cannot set the response content twice.");
|
||||
}//else//
|
||||
}//acceptWebSocketUpgrade()//
|
||||
/**
|
||||
* Gets the character set used by the content (if text).
|
||||
* @return The content's character set.
|
||||
@@ -258,7 +291,6 @@ public void setHeader(String header) {
|
||||
|
||||
headerLines = header.substring(0, header.length() - 4).split("\r\n");
|
||||
|
||||
|
||||
headerFieldNames = new LiteList(headerLines.length - 1);
|
||||
headerFieldMap = new LiteHashMap(headerLines.length + 10);
|
||||
//Place the response line (first line in the header).//
|
||||
|
||||
Reference in New Issue
Block a user