Skip to content

Commit f64bd7b

Browse files
committed
Avoid returns as parameters
1 parent 2865cfd commit f64bd7b

File tree

2 files changed

+20
-68
lines changed

2 files changed

+20
-68
lines changed

src/http_response.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,6 @@ http_response::~http_response()
7373
webserver::unlock_cache_entry(ce);
7474
}
7575

76-
size_t http_response::get_headers(std::map<std::string, std::string, http::header_comparator>& result) const
77-
{
78-
result = this->headers;
79-
return result.size();
80-
}
81-
82-
size_t http_response::get_footers(std::map<std::string, std::string, http::header_comparator>& result) const
83-
{
84-
result = this->footers;
85-
return result.size();
86-
}
87-
88-
size_t http_response::get_cookies(std::map<std::string, std::string, http::header_comparator>& result) const
89-
{
90-
result = this->cookies;
91-
return result.size();
92-
}
93-
9476
//RESPONSE
9577
void http_response::get_raw_response_str(MHD_Response** response, webserver* ws)
9678
{

src/httpserver/http_response.hpp

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -113,75 +113,58 @@ class http_response
113113
* Method used to get the content from the response.
114114
* @return the content in string form
115115
**/
116-
std::string get_content()
116+
const std::string& get_content()
117117
{
118118
return this->content;
119119
}
120120

121-
void get_content(std::string& result)
122-
{
123-
result = this->content;
124-
}
125-
126121
/**
127122
* Method used to get a specified header defined for the response
128123
* @param key The header identification
129124
* @return a string representing the value assumed by the header
130125
**/
131-
std::string get_header(const std::string& key)
126+
const std::string& get_header(const std::string& key)
132127
{
133128
return this->headers[key];
134129
}
135130

136-
void get_header(const std::string& key, std::string& result)
137-
{
138-
result = this->headers[key];
139-
}
140-
141131
/**
142132
* Method used to get a specified footer defined for the response
143133
* @param key The footer identification
144134
* @return a string representing the value assumed by the footer
145135
**/
146-
std::string get_footer(const std::string& key)
136+
const std::string& get_footer(const std::string& key)
147137
{
148138
return this->footers[key];
149139
}
150140

151-
void get_footer(const std::string& key, std::string& result)
152-
{
153-
result = this->footers[key];
154-
}
155-
156-
std::string get_cookie(const std::string& key)
141+
const std::string& get_cookie(const std::string& key)
157142
{
158143
return this->cookies[key];
159144
}
160145

161-
void get_cookie(const std::string& key, std::string& result)
162-
{
163-
result = this->cookies[key];
164-
}
165-
166146
/**
167147
* Method used to get all headers passed with the request.
168148
* @return a map<string,string> containing all headers.
169149
**/
170-
size_t get_headers(
171-
std::map<std::string, std::string, http::header_comparator>& result
172-
) const;
150+
const std::map<std::string, std::string, http::header_comparator>& get_headers() const
151+
{
152+
return this->headers;
153+
}
173154

174155
/**
175156
* Method used to get all footers passed with the request.
176157
* @return a map<string,string> containing all footers.
177158
**/
178-
size_t get_footers(
179-
std::map<std::string, std::string, http::header_comparator>& result
180-
) const;
159+
const std::map<std::string, std::string, http::header_comparator>& get_footers() const
160+
{
161+
return this->footers;
162+
}
181163

182-
size_t get_cookies(
183-
std::map<std::string, std::string, http::header_comparator>& result
184-
) const;
164+
const std::map<std::string, std::string, http::header_comparator>& get_cookies() const
165+
{
166+
return this->cookies;
167+
}
185168

186169
/**
187170
* Method used to get the response code from the response
@@ -192,26 +175,16 @@ class http_response
192175
return this->response_code;
193176
}
194177

195-
std::string get_realm() const
178+
const std::string& get_realm() const
196179
{
197180
return this->realm;
198181
}
199182

200-
void get_realm(std::string& result) const
201-
{
202-
result = this->realm;
203-
}
204-
205-
std::string get_opaque() const
183+
const std::string& get_opaque() const
206184
{
207185
return this->opaque;
208186
}
209187

210-
void get_opaque(std::string& result) const
211-
{
212-
result = this->opaque;
213-
}
214-
215188
bool need_nonce_reload() const
216189
{
217190
return this->reload_nonce;
@@ -227,12 +200,9 @@ class http_response
227200
return autodelete;
228201
}
229202

230-
size_t get_topics(std::vector<std::string>& topics) const
203+
const std::vector<std::string>& get_topics() const
231204
{
232-
typedef std::vector<std::string>::const_iterator topics_it;
233-
for(topics_it it=this->topics.begin();it != this->topics.end();++it)
234-
topics.push_back(*it);
235-
return topics.size();
205+
return this->topics;
236206
}
237207
protected:
238208
typedef details::binders::functor_two<MHD_Response**, webserver*, void> get_raw_response_t;

0 commit comments

Comments
 (0)