Hi.
I have a custom module in which i reject the httpSession using the rejectClient() method if i don’t find a specific header with a specific value.
It’s mostly working but i am getting mixed results, on average only 4 in 10 requests get blocked and receive 403, the rest get 200, i am using curl and ffprobe to test, and querying http://server/applicationname/stream/playlist.m3u8 in my tests. Also, when i test with the same url and use vlc, it always plays the stream.
Any new ideas of what i might be missing are very appreciated.
Here is the code:
package com.company.wowza.wms.module;
import com.wowza.wms.application.IApplicationInstance;
import com.wowza.wms.httpstreamer.model.*;
import com.wowza.wms.module.*;
public class ModuleAccessControlHTTPStreaming extends ModuleBase {
static String allowedHeaderName;
static String allowedHeaderValue;
public void onAppStart(IApplicationInstance appInstance) {
String fullname = appInstance.getApplication().getName() + "/" + appInstance.getName();
getLogger().info("ModuleAccessControlHTTPStreaming, onAppStart app: " + fullname);
allowedHeaderName = appInstance.getProperties()
.getPropertyStr("ModuleAccessControlHTTPStreamingHeaderName", "CF_EDGE_SERVER");
allowedHeaderValue = appInstance.getProperties()
.getPropertyStr("ModuleAccessControlHTTPStreamingHeaderValue", "TRUE");
getLogger().debug("ModuleAccessControlHTTPStreaming, Properties H: " + allowedHeaderName + ", V: " + allowedHeaderValue);
}
public void onHTTPSessionCreate(IHTTPStreamerSession httpSession) {
boolean rejectClient = true;
String userAgent = httpSession.getUserAgent();
String ipAddressClient = httpSession.getIpAddress();
java.util.Map<String,String> HTTPHeaders = httpSession.getHTTPHeaderMap();
for(java.util.Map.Entry<String, String> header : HTTPHeaders.entrySet()) {
String headerName = header.getKey();
String headerValue = header.getValue();
getLogger().debug("ModuleAccessControlHTTPStreaming, H: " + headerName + ", V: " + headerValue);
if (
headerName.equalsIgnoreCase(allowedHeaderName) &&
headerValue.equalsIgnoreCase(allowedHeaderValue)
) {
rejectClient = false;
break;
}
}
if (rejectClient) {
getLogger().warn("ModuleAccessControlHTTPStreaming, Client Rejected, UA: " + userAgent + ", IP: " + ipAddressClient);
httpSession.rejectSession();
} else
getLogger().info("ModuleAccessControlHTTPStreaming, Client Accepted, UA: " + userAgent + ", IP: " + ipAddressClient);
}
}
P.S. If my code has no design and/or logic flaws/bugs, it could be that this might be a bug in the java api.