Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.7.13 http listeners #631

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
eebafe9
Add 307 redirect to AuthorizationListener
Nov 24, 2018
b1e462e
Add AuthorizationResponseActions; Add custom data string to client
Nov 27, 2018
b918df7
Load initial authorization data into store
Nov 27, 2018
252aafa
Add X-Error-Message header and 400 Bad Request
Dec 10, 2018
d13e3d1
Add more possible responses
Dec 10, 2018
0199627
Use HttpResponseStatus instead Action
Dec 10, 2018
da35949
Improve
Dec 10, 2018
30e68ca
Add CustomRequestListener
Dec 11, 2018
1f390e9
Refactor HttpRequestListener
Dec 11, 2018
f38b6b3
Fix missing body
Dec 15, 2018
d5dea1d
Fix Charset -> UTF-8
Dec 15, 2018
bbdde1b
Add IDEA to gitignore
Dec 15, 2018
a8dc7a7
Add HttpListeners
Dec 15, 2018
ad9fc78
Commit missing file
Dec 15, 2018
b0bf469
Improve naming; Throw INTERNAL_SERVER_ERROR when httpListener code th…
Dec 15, 2018
bd290ce
Fix missing response body issue
Dec 15, 2018
0d96a98
dto.
Dec 15, 2018
06e1820
Add handling of Content-Type
Dec 15, 2018
b0fe52a
Change misleading comment
Dec 15, 2018
153cb7b
Fix issue with wrong header naming
Dec 15, 2018
6860c12
Switch order of contentType and charset in signatures; Remove charset…
Dec 15, 2018
c546e50
Remove space in front of charset
Dec 15, 2018
a061864
Change String to ByteArray before pushing into Netty for body; Change…
Dec 19, 2018
5086756
Fix NPE because underlying class delivers null instead []
Dec 21, 2018
700383d
Fix NPE
Dec 22, 2018
892ff45
Fix WrongUrlHandler: return 404 on wrong path instead 400
Dec 22, 2018
7bdc165
Fix issue with hanging connection
Dec 26, 2018
96ec49c
Do not allow returning body in AuthorizationResponse; Use AsciiString…
Dec 29, 2018
787ad8a
Move EncoderHandler before HttpRequestHandler for CORS settings in http
Dec 29, 2018
c434d2a
Split AuthorizationResponse in AuthorizedResponse and UnauthorizedRes…
Dec 29, 2018
9ebe987
Add HttpRequestSignature to HttpListener as argument
Dec 29, 2018
962e62e
Add getNames() in HttpParams; Fix wrong naming
Dec 29, 2018
3678900
Add getter to HttpParams
Dec 29, 2018
cc730a6
Rename toParams() -> asMap()
Dec 29, 2018
8fb13b0
Log and continue instead ignoring if AuthorizationListener or HttpLis…
Dec 29, 2018
08166a8
Merge namespace fix from newer version
Jan 6, 2019
a76baea
Remove invisible character
Jan 6, 2019
35a22cd
Add multimap signature for adding HttpHeaders
Jan 13, 2019
3cf2569
Add throws to HttpListener interface
Jan 13, 2019
f97732b
Fix NPE when wrong number of arguments is sent by client
Jan 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,14 @@
/target

/gnupg

# Intellij IDEA (see https://intellij-support.jetbrains.com/entries/23393067)
.idea/
release.properties
.navigation/
captures/
*.iws
*.iml
*.ipr
*~
*.swp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
public interface AuthorizationListener {

/**
* Checks is client with handshake data is authorized
* Checks if client with handshake data is authorized
*
* @param data - handshake data
* @return - <b>true</b> if client is authorized of <b>false</b> otherwise
* @return - <b>AuthorizationResponse</b>
*/
boolean isAuthorized(HandshakeData data);
AuthorizationResponse authorize(HandshakeData data);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2012 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.corundumstudio.socketio;

import io.netty.handler.codec.http.HttpResponseStatus;

public abstract class AuthorizationResponse {

private final HttpResponseStatus httpResponseStatus;

protected AuthorizationResponse(HttpResponseStatus httpResponseStatus) {
this.httpResponseStatus = httpResponseStatus;
}

public HttpResponseStatus getHttpResponseStatus() {
return httpResponseStatus;
}

}
56 changes: 56 additions & 0 deletions src/main/java/com/corundumstudio/socketio/AuthorizedResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright 2012 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.corundumstudio.socketio;

import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.AsciiString;

import java.util.HashMap;
import java.util.Map;

/*
* Used to authorize client and add data to the client store
*/
public class AuthorizedResponse extends AuthorizationResponse {

private final Map<String, Object> clientData = new HashMap<String, Object>();

public AuthorizedResponse() {
super(HttpResponseStatus.OK);
}

public static AuthorizedResponse OK() {
return new AuthorizedResponse();
}

public AuthorizedResponse setClientData(String key, Object value) {
clientData.put(key, value);
return this;
}

public AuthorizedResponse setClientData(Map<String, Object> map) {
clientData.putAll(map);
return this;
}


public Map<String, Object> getClientData() {
return clientData;
}

}
28 changes: 4 additions & 24 deletions src/main/java/com/corundumstudio/socketio/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/
package com.corundumstudio.socketio;

import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

import com.corundumstudio.socketio.handler.SuccessAuthorizationListener;
import com.corundumstudio.socketio.listener.DefaultExceptionListener;
import com.corundumstudio.socketio.listener.ExceptionListener;
Expand All @@ -27,6 +23,9 @@
import com.corundumstudio.socketio.store.StoreFactory;

import javax.net.ssl.KeyManagerFactory;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

public class Configuration {

Expand All @@ -40,8 +39,6 @@ public class Configuration {
private int workerThreads = 0; // 0 = current_processors_amount * 2
private boolean useLinuxNativeEpoll;

private boolean allowCustomRequests = false;

private int upgradeTimeout = 10000;
private int pingTimeout = 60000;
private int pingInterval = 25000;
Expand Down Expand Up @@ -122,7 +119,6 @@ public Configuration() {

setJsonSupport(new JsonSupportWrapper(conf.getJsonSupport()));
setContext(conf.getContext());
setAllowCustomRequests(conf.isAllowCustomRequests());

setKeyStorePassword(conf.getKeyStorePassword());
setKeyStore(conf.getKeyStore());
Expand Down Expand Up @@ -239,22 +235,6 @@ public void setContext(String context) {
this.context = context;
}

public boolean isAllowCustomRequests() {
return allowCustomRequests;
}

/**
* Allow to service custom requests differs from socket.io protocol.
* In this case it's necessary to add own handler which handle them
* to avoid hang connections.
* Default is {@code false}
*
* @param allowCustomRequests - {@code true} to allow
*/
public void setAllowCustomRequests(boolean allowCustomRequests) {
this.allowCustomRequests = allowCustomRequests;
}

/**
* SSL key store password
*
Expand Down Expand Up @@ -460,7 +440,7 @@ public void setKeyManagerFactoryAlgorithm(String keyManagerFactoryAlgorithm) {
/**
* Set maximum websocket frame content length limit
*
* @param maxContentLength
* @param maxFramePayloadLength
*/
public void setMaxFramePayloadLength(int maxFramePayloadLength) {
this.maxFramePayloadLength = maxFramePayloadLength;
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/com/corundumstudio/socketio/HttpParams.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.corundumstudio.socketio;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class HttpParams {
private final Map<String, List<String>> params;

public HttpParams(Map<String, List<String>> params) {
this.params = params;
}

public Set<String> getNames() {
return params.keySet();
}

public String get(String name) {
List<String> values = getAll(name);
if (values == null || values.isEmpty()) return null;

return values.get(0);
}

public List<String> getAll(String name) {
return params.get(name);
}

public Map<String, List<String>> asMap() {
return params;
}

@Override
public String toString() {
return params.toString();
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/corundumstudio/socketio/HttpRequestBody.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.corundumstudio.socketio;

import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.util.CharsetUtil;

import java.nio.charset.Charset;

public class HttpRequestBody {

private final FullHttpRequest req;

public HttpRequestBody(FullHttpRequest req) {
this.req = req;
}

public String toString() {
return toString(CharsetUtil.UTF_8);
}

public String toString(Charset charset) {
ByteBuf buffer = req.content();
return buffer.toString(charset);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.corundumstudio.socketio;

import io.netty.handler.codec.http.HttpMethod;

public class HttpRequestSignature {
private final HttpMethod httpMethod;
private final String path;

public HttpRequestSignature(HttpMethod httpMethod, String path) {
this.httpMethod = httpMethod;
this.path = path;
}

public HttpMethod getHttpMethod() {
return httpMethod;
}

public String getPath() {
return path;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof HttpRequestSignature)) return false;

HttpRequestSignature that = (HttpRequestSignature) o;

if (!httpMethod.equals(that.httpMethod)) return false;
return path.equals(that.path);
}

@Override
public int hashCode() {
int result = httpMethod.hashCode();
result = 31 * result + path.hashCode();
return result;
}
}
Loading