Skip to content

Commit

Permalink
Avoid #includes with a surrounding namespace (#7560)
Browse files Browse the repository at this point in the history
untangle the namespace/double inclusions in webserver library.
This is a followup of the discussion in
#6946 (comment)
  • Loading branch information
dirkmueller committed Sep 17, 2020
1 parent e5c84c9 commit 32470fb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ static const char qop_auth_quoted[] PROGMEM = "qop=\"auth\"";
static const char WWW_Authenticate[] PROGMEM = "WWW-Authenticate";
static const char Content_Length[] PROGMEM = "Content-Length";

namespace esp8266webserver {

template <typename ServerType>
ESP8266WebServerTemplate<ServerType>::ESP8266WebServerTemplate(IPAddress addr, int port)
: _server(addr, port)
Expand Down Expand Up @@ -864,3 +866,5 @@ String ESP8266WebServerTemplate<ServerType>::responseCodeToString(const int code
}
return String(r);
}

} // namespace
8 changes: 5 additions & 3 deletions libraries/ESP8266WebServer/src/ESP8266WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ namespace esp8266webserver {
template<typename ServerType>
class ESP8266WebServerTemplate;

}

#include "detail/RequestHandler.h"

namespace esp8266webserver {

template<typename ServerType>
class ESP8266WebServerTemplate
{
Expand Down Expand Up @@ -296,13 +300,11 @@ class ESP8266WebServerTemplate
HookFunction _hook;
};

} // namespace

#include "ESP8266WebServer-impl.h"
#include "Parsing-impl.h"

};


using ESP8266WebServer = esp8266webserver::ESP8266WebServerTemplate<WiFiServer>;
using RequestHandler = esp8266webserver::RequestHandler<WiFiServer>;

Expand Down
4 changes: 4 additions & 0 deletions libraries/ESP8266WebServer/src/Parsing-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
static const char Content_Type[] PROGMEM = "Content-Type";
static const char filename[] PROGMEM = "filename";

namespace esp8266webserver {

template <typename ServerType>
static bool readBytesWithTimeout(typename ServerType::ClientType& client, size_t maxLength, String& data, int timeout_ms)
{
Expand Down Expand Up @@ -578,3 +580,5 @@ bool ESP8266WebServerTemplate<ServerType>::_parseFormUploadAborted(){
_currentHandler->upload(*this, _currentUri, *_currentUpload);
return false;
}

} // namespace
4 changes: 4 additions & 0 deletions libraries/ESP8266WebServer/src/detail/RequestHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <vector>
#include <assert.h>

namespace esp8266webserver {

template<typename ServerType>
class RequestHandler {
using WebServerType = ESP8266WebServerTemplate<ServerType>;
Expand All @@ -31,4 +33,6 @@ class RequestHandler {
}
};

} // namespace

#endif //REQUESTHANDLER_H
4 changes: 3 additions & 1 deletion libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "WString.h"
#include "Uri.h"

using namespace mime;
namespace esp8266webserver {

template<typename ServerType>
class FunctionRequestHandler : public RequestHandler<ServerType> {
Expand Down Expand Up @@ -126,6 +126,7 @@ class StaticRequestHandler : public RequestHandler<ServerType> {

String contentType = mime::getContentType(path);

using namespace mime;
// look for gz file, only if the original specified path is not a gz. So part only works to send gzip via content encoding when a non compressed is asked for
// if you point the the path to gzip you will serve the gzip as content type "application/x-gzip", not text or javascript etc...
if (!path.endsWith(FPSTR(mimeTable[gz].endsWith)) && !_fs.exists(path)) {
Expand Down Expand Up @@ -164,5 +165,6 @@ class StaticRequestHandler : public RequestHandler<ServerType> {
size_t _baseUriLength;
};

} // namespace

#endif //REQUESTHANDLERSIMPL_H

0 comments on commit 32470fb

Please sign in to comment.