-
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved the HttpServer Plugins demo to a separate sample application.
- Loading branch information
1 parent
bf3d5a3
commit 48f39b5
Showing
9 changed files
with
373 additions
and
53 deletions.
There are no files selected for viewing
37 changes: 0 additions & 37 deletions
37
Sming/Components/Network/src/Network/Http/Resource/Content/DecoderContent.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage"> | ||
<storageModule moduleId="org.eclipse.cdt.core.settings"> | ||
<cconfiguration id="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147"> | ||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147" moduleId="org.eclipse.cdt.core.settings" name="Sming"> | ||
<externalSettings/> | ||
<extensions> | ||
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> | ||
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | ||
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | ||
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | ||
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> | ||
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> | ||
</extensions> | ||
</storageModule> | ||
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> | ||
<configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147" name="Sming" parent="org.eclipse.cdt.build.core.emptycfg"> | ||
<folderInfo id="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463" name="/" resourcePath=""> | ||
<toolChain id="cdt.managedbuild.toolchain.gnu.cross.base.1164554300" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.base"> | ||
<option id="cdt.managedbuild.option.gnu.cross.prefix.521205673" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix"/> | ||
<option id="cdt.managedbuild.option.gnu.cross.path.393887888" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path"/> | ||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.712123812" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/> | ||
<builder id="cdt.managedbuild.builder.gnu.cross.2110485170" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/> | ||
<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.1168221903" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler"> | ||
<option id="gnu.c.compiler.option.include.paths.357494572" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> | ||
<listOptionValue builtIn="false" value=""${SMING_HOME}""/> | ||
<listOptionValue builtIn="false" value=""${SMING_HOME}/system/include""/> | ||
<listOptionValue builtIn="false" value=""${SMING_HOME}/Libraries""/> | ||
<listOptionValue builtIn="false" value=""${ESP_HOME}/sdk/include""/> | ||
</option> | ||
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.313321806" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> | ||
</tool> | ||
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.1999763015" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler"> | ||
<option id="gnu.cpp.compiler.option.include.paths.611746109" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> | ||
<listOptionValue builtIn="false" value=""${SMING_HOME}""/> | ||
<listOptionValue builtIn="false" value=""${SMING_HOME}/system/include""/> | ||
<listOptionValue builtIn="false" value=""${SMING_HOME}/Libraries""/> | ||
<listOptionValue builtIn="false" value=""${ESP_HOME}/sdk/include""/> | ||
</option> | ||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1330530366" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> | ||
</tool> | ||
<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.65193859" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker"/> | ||
<tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.1795850540" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker"> | ||
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.364843833" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> | ||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> | ||
<additionalInput kind="additionalinput" paths="$(LIBS)"/> | ||
</inputType> | ||
</tool> | ||
<tool id="cdt.managedbuild.tool.gnu.cross.archiver.525412186" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/> | ||
<tool id="cdt.managedbuild.tool.gnu.cross.assembler.587940548" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler"> | ||
<option id="gnu.both.asm.option.include.paths.1067006329" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath"> | ||
<listOptionValue builtIn="false" value=""${SMING_HOME}""/> | ||
<listOptionValue builtIn="false" value=""${SMING_HOME}/system/include""/> | ||
<listOptionValue builtIn="false" value=""${SMING_HOME}/Libraries""/> | ||
<listOptionValue builtIn="false" value=""${ESP_HOME}/sdk/include""/> | ||
</option> | ||
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.651581712" superClass="cdt.managedbuild.tool.gnu.assembler.input"/> | ||
</tool> | ||
</toolChain> | ||
</folderInfo> | ||
</configuration> | ||
</storageModule> | ||
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> | ||
</cconfiguration> | ||
</storageModule> | ||
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> | ||
<project id="HttpServer_AJAX.null.1347473968" name="HttpServer_AJAX"/> | ||
</storageModule> | ||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> | ||
<storageModule moduleId="refreshScope" versionNumber="2"> | ||
<configuration configurationName="Sming"> | ||
<resource resourceType="PROJECT" workspacePath="/HttpServer_AJAX"/> | ||
</configuration> | ||
</storageModule> | ||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"> | ||
<buildTargets> | ||
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> | ||
<buildCommand>make</buildCommand> | ||
<buildArguments>-f ${ProjDirPath}/Makefile</buildArguments> | ||
<buildTarget>all</buildTarget> | ||
<stopOnError>true</stopOnError> | ||
<useDefaultCommand>true</useDefaultCommand> | ||
<runAllBuilders>true</runAllBuilders> | ||
</target> | ||
<target name="clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> | ||
<buildCommand>make</buildCommand> | ||
<buildArguments>-f ${ProjDirPath}/Makefile</buildArguments> | ||
<buildTarget>clean</buildTarget> | ||
<stopOnError>true</stopOnError> | ||
<useDefaultCommand>true</useDefaultCommand> | ||
<runAllBuilders>true</runAllBuilders> | ||
</target> | ||
<target name="flash" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> | ||
<buildCommand>make</buildCommand> | ||
<buildArguments>-f ${ProjDirPath}/Makefile</buildArguments> | ||
<buildTarget>flash</buildTarget> | ||
<stopOnError>true</stopOnError> | ||
<useDefaultCommand>true</useDefaultCommand> | ||
<runAllBuilders>true</runAllBuilders> | ||
</target> | ||
<target name="flashonefile" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> | ||
<buildCommand>make</buildCommand> | ||
<buildArguments>-f ${ProjDirPath}/Makefile</buildArguments> | ||
<buildTarget>flashonefile</buildTarget> | ||
<stopOnError>true</stopOnError> | ||
<useDefaultCommand>true</useDefaultCommand> | ||
<runAllBuilders>true</runAllBuilders> | ||
</target> | ||
<target name="flashinit" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> | ||
<buildCommand>make</buildCommand> | ||
<buildArguments>-f ${ProjDirPath}/Makefile</buildArguments> | ||
<buildTarget>flashinit</buildTarget> | ||
<stopOnError>true</stopOnError> | ||
<useDefaultCommand>true</useDefaultCommand> | ||
<runAllBuilders>true</runAllBuilders> | ||
</target> | ||
<target name="flashboot" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> | ||
<buildCommand>make</buildCommand> | ||
<buildArguments>-f ${ProjDirPath}/Makefile</buildArguments> | ||
<buildTarget>flashboot</buildTarget> | ||
<stopOnError>true</stopOnError> | ||
<useDefaultCommand>true</useDefaultCommand> | ||
<runAllBuilders>true</runAllBuilders> | ||
</target> | ||
<target name="rebuild" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> | ||
<buildCommand>make</buildCommand> | ||
<buildArguments>-f ${ProjDirPath}/Makefile</buildArguments> | ||
<buildTarget>rebuild</buildTarget> | ||
<stopOnError>true</stopOnError> | ||
<useDefaultCommand>true</useDefaultCommand> | ||
<runAllBuilders>true</runAllBuilders> | ||
</target> | ||
</buildTargets> | ||
</storageModule> | ||
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/> | ||
<storageModule moduleId="scannerConfiguration"> | ||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> | ||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.c.compiler.mingw.base.2032390008;cdt.managedbuild.tool.gnu.c.compiler.input.1700912488"> | ||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> | ||
</scannerConfigBuildInfo> | ||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.cross.c.compiler.1168221903;cdt.managedbuild.tool.gnu.c.compiler.input.313321806"> | ||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> | ||
</scannerConfigBuildInfo> | ||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.cross.cpp.compiler.1999763015;cdt.managedbuild.tool.gnu.cpp.compiler.input.1330530366"> | ||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> | ||
</scannerConfigBuildInfo> | ||
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.1135534147;cdt.managedbuild.toolchain.gnu.mingw.base.1135534147.86962463;cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.454898447;cdt.managedbuild.tool.gnu.cpp.compiler.input.501261625"> | ||
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> | ||
</scannerConfigBuildInfo> | ||
</storageModule> | ||
</cproject> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>HttpServer_Plugins</name> | ||
<comment></comment> | ||
<projects> | ||
<project>SmingFramework</project> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> | ||
<triggers>clean,full,incremental,</triggers> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name> | ||
<triggers>full,incremental,</triggers> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.cdt.core.cnature</nature> | ||
<nature>org.eclipse.cdt.core.ccnature</nature> | ||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> | ||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
##################################################################### | ||
#### Please don't change this file. Use component.mk instead #### | ||
##################################################################### | ||
|
||
ifndef SMING_HOME | ||
$(error SMING_HOME is not set: please configure it as an environment variable) | ||
endif | ||
|
||
include $(SMING_HOME)/project.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
HttpServer Plugins | ||
===================== | ||
|
||
Simple example that demonstrate extending the HttpServer functionality with additional plugins. | ||
Using such examples one can add: | ||
|
||
- URL Rewriting | ||
- Authentication. Sming has already existing plugins for Basic Authentication, IP Limiting | ||
- Content extracting/processing. For example a gzip decoder plugin can be implemented. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include <SmingCore.h> | ||
#include <Network/Http/Websocket/WebsocketResource.h> | ||
#include <Network/Http/Resource/HttpAuth.h> | ||
#include "ContentDecoderPlugin.h" | ||
|
||
// If you want, you can define WiFi settings globally in Eclipse Environment Variables | ||
#ifndef WIFI_SSID | ||
#define WIFI_SSID "PleaseEnterSSID" // Put your SSID and password here | ||
#define WIFI_PWD "PleaseEnterPass" | ||
#endif | ||
|
||
namespace | ||
{ | ||
HttpServer server; | ||
|
||
void echoContentBody(HttpRequest& request, HttpResponse& response) | ||
{ | ||
auto body = request.getBody(); | ||
debug_d("Got content (after modifications): %s", body.c_str()); | ||
|
||
response.headers[HTTP_HEADER_CONTENT_TYPE] = request.headers[HTTP_HEADER_CONTENT_TYPE]; | ||
response.sendString(body); | ||
} | ||
|
||
void startWebServer() | ||
{ | ||
server.listen(80); | ||
server.paths.set("/", echoContentBody); | ||
server.paths.setDefault(echoContentBody); | ||
|
||
/* | ||
* By default the server does not store the incoming information. | ||
* There has to be either a plugin that does this or a body parser. | ||
* In this sample we use a body parser that stores the information into memory. | ||
*/ | ||
server.setBodyParser(MIME_FORM_URL_ENCODED, bodyToStringParser); | ||
|
||
// Here we use a simple plugin that protects the access to a resource using HTTP Basic Authentication | ||
auto pluginBasicAuth = new ResourceBasicAuth("realm", "username", "password"); | ||
// You can add one or more authentication methods or other plugins... | ||
server.paths.set("/auth", echoContentBody, pluginBasicAuth); | ||
|
||
/* | ||
* The plugins will be registered in the order in which they are provided. | ||
* For example in the command below the IP restriction plugin will be registered first | ||
* followed by the basic authentication plugin. | ||
* You can run the following curl command to test these plugins: | ||
* | ||
* curl -vvv http://username:[email protected]/ip-n-auth | ||
* | ||
* make sure to replace the IP address with the IP address of your HttpServer | ||
*/ | ||
server.paths.set("/ip-n-auth", echoContentBody, | ||
new ResourceIpAuth(IpAddress("192.168.13.0"), IpAddress("255.255.255.0")), pluginBasicAuth); | ||
|
||
/* | ||
* This content coming to this resource is modified on the fly | ||
* using our ContentDecoderPlugin. See the source code of ContentDecoderPlugin | ||
* to get an idea how to create your own plugin. | ||
* You can run the following curl command to test this plugin: | ||
* | ||
* curl -vvv http://[email protected]/test -d "text=1" -H "Content-Encoding: test" | ||
* | ||
* make sure to replace the IP address with the IP address of your HttpServer | ||
*/ | ||
server.paths.set("/test", echoContentBody, new ContentDecoderPlugin()); | ||
|
||
Serial.println(F("\r\n=== WEB SERVER STARTED ===")); | ||
Serial.println(WifiStation.getIP()); | ||
Serial.println(F("==============================\r\n")); | ||
} | ||
|
||
// Will be called when WiFi station becomes fully operational | ||
void gotIP(IpAddress ip, IpAddress netmask, IpAddress gateway) | ||
{ | ||
startWebServer(); | ||
} | ||
|
||
} // namespace | ||
|
||
void init() | ||
{ | ||
Serial.begin(SERIAL_BAUD_RATE); // 115200 by default | ||
Serial.systemDebugOutput(true); // Enable debug output to serial | ||
|
||
WifiStation.enable(true); | ||
WifiStation.config(WIFI_SSID, WIFI_PWD); | ||
WifiAccessPoint.enable(false); | ||
|
||
// Run our method when station was connected to AP | ||
WifiEvents.onStationGotIP(gotIP); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
HWCONFIG := standard |
Oops, something went wrong.