Skip to content

Commit 08d7df1

Browse files
committed
Use const references for strings that are used read-only fhessel#37
1 parent 013436f commit 08d7df1

20 files changed

+46
-46
lines changed

src/HTTPConnection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ void handleWebsocketHandshake(HTTPRequest * req, HTTPResponse * res) {
633633
/**
634634
* Function used to compute the value of the Sec-WebSocket-Accept during Websocket handshake
635635
*/
636-
std::string websocketKeyResponseHash(std::string key) {
636+
std::string websocketKeyResponseHash(std::string const &key) {
637637
std::string newKey = key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
638638
uint8_t shaData[HTTPS_SHA1_LENGTH];
639639
esp_sha(SHA1, (uint8_t*)newKey.data(), newKey.length(), shaData);

src/HTTPConnection.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ class HTTPConnection : private ConnectionContext {
119119
size_t readBuffer(byte* buffer, size_t length);
120120
size_t getCacheSize();
121121
bool checkWebsocket();
122-
std::string websocketKeyResponseHash(std::string key);
123122

124123
// The receive buffer
125124
char _receiveBuffer[HTTPS_CONNECTION_DATA_CHUNK_SIZE];
@@ -161,7 +160,7 @@ class HTTPConnection : private ConnectionContext {
161160

162161
void handleWebsocketHandshake(HTTPRequest * req, HTTPResponse * res);
163162

164-
std::string websocketKeyResponseHash(std::string key);
163+
std::string websocketKeyResponseHash(std::string const &key);
165164

166165
void validationMiddleware(HTTPRequest * req, HTTPResponse * res, std::function<void()> next);
167166

src/HTTPHeader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace httpsserver {
44

5-
HTTPHeader::HTTPHeader(const std::string name, const std::string value):
6-
_name(std::move(name)),
7-
_value(std::move(value)) {
8-
5+
HTTPHeader::HTTPHeader(const std::string &name, const std::string &value):
6+
_name(name),
7+
_value(value) {
8+
Serial.printf("Header Constructor: %s=%s\n4", name.c_str(), value.c_str());
99
}
1010

1111
HTTPHeader::~HTTPHeader() {

src/HTTPHeader.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#ifndef SRC_HTTPHEADER_HPP_
22
#define SRC_HTTPHEADER_HPP_
3+
#include <Arduino.h>
34

45
#include <string>
56

67
namespace httpsserver {
78

89
class HTTPHeader {
910
public:
10-
HTTPHeader(const std::string name, const std::string value);
11+
HTTPHeader(const std::string &name, const std::string &value);
1112
virtual ~HTTPHeader();
1213
const std::string _name;
1314
const std::string _value;

src/HTTPHeaders.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ HTTPHeaders::~HTTPHeaders() {
1212
delete _headers;
1313
}
1414

15-
HTTPHeader * HTTPHeaders::get(const std::string name) {
15+
HTTPHeader * HTTPHeaders::get(std::string const &name) {
1616
for(std::vector<HTTPHeader*>::iterator header = _headers->begin(); header != _headers->end(); ++header) {
1717
if ((*header)->_name.compare(name)==0) {
1818
return (*header);
@@ -21,7 +21,7 @@ HTTPHeader * HTTPHeaders::get(const std::string name) {
2121
return NULL;
2222
}
2323

24-
std::string HTTPHeaders::getValue(std::string name) {
24+
std::string HTTPHeaders::getValue(std::string const &name) {
2525
for(std::vector<HTTPHeader*>::iterator header = _headers->begin(); header != _headers->end(); ++header) {
2626
if ((*header)->_name.compare(name)==0) {
2727
return ((*header)->_value);

src/HTTPHeaders.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class HTTPHeaders {
1717
HTTPHeaders();
1818
virtual ~HTTPHeaders();
1919

20-
HTTPHeader * get(std::string name);
21-
std::string getValue(std::string name);
20+
HTTPHeader * get(std::string const &name);
21+
std::string getValue(std::string const &name);
2222
void set(HTTPHeader * header);
2323

2424
std::vector<HTTPHeader *> * getAll();

src/HTTPNode.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace httpsserver {
44

5-
HTTPNode::HTTPNode(const std::string path, const HTTPNodeType nodeType, const std::string tag):
6-
_path(std::move(path)),
7-
_tag(std::move(tag)),
5+
HTTPNode::HTTPNode(std::string const &path, const HTTPNodeType nodeType, std::string const &tag):
6+
_path(path),
7+
_tag(tag),
88
_nodeType(nodeType) {
99

1010
// Create vector for valdiators

src/HTTPNode.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ enum HTTPNodeType {
1919

2020
class HTTPNode {
2121
public:
22-
HTTPNode(const std::string path, const HTTPNodeType nodeType, const std::string tag = "");
22+
HTTPNode(const std::string &path, const HTTPNodeType nodeType, const std::string &tag = "");
2323
virtual ~HTTPNode();
2424

2525
/**

src/HTTPRequest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ResourceParameters * HTTPRequest::getParams() {
3636
return _params;
3737
}
3838

39-
std::string HTTPRequest::getHeader(std::string name) {
39+
std::string HTTPRequest::getHeader(std::string const &name) {
4040
HTTPHeader * h = _headers->get(name);
4141
if (h != NULL) {
4242
return h->_value;
@@ -45,7 +45,7 @@ std::string HTTPRequest::getHeader(std::string name) {
4545
}
4646
}
4747

48-
void HTTPRequest::setHeader(std::string name, std::string value) {
48+
void HTTPRequest::setHeader(std::string const &name, std::string const &value) {
4949
_headers->set(new HTTPHeader(name, value));
5050
}
5151

src/HTTPRequest.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class HTTPRequest {
2020
HTTPRequest(ConnectionContext * con, HTTPHeaders * headers, HTTPNode * resolvedNode, std::string method, ResourceParameters * params, std::string requestString);
2121
virtual ~HTTPRequest();
2222

23-
std::string getHeader(std::string name);
24-
void setHeader(std::string name, std::string value);
23+
std::string getHeader(std::string const &name);
24+
void setHeader(std::string const &name, std::string const &value);
2525
HTTPNode * getResolvedNode();
2626
std::string getRequestString();
2727
std::string getMethod();

0 commit comments

Comments
 (0)