Skip to content

Commit 37c992a

Browse files
committed
fix: microscopic errors
1 parent e16b973 commit 37c992a

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

src/config/config_builder.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515

1616
static void config_error(const std::string& msg, int line = -1)
1717
{
18-
if (line != -1) {
19-
throw std::runtime_error(msg + " (line " + itoa(line) + ")");
20-
}
21-
else {
18+
if (line == -1)
2219
throw std::runtime_error(msg);
23-
}
20+
21+
throw std::runtime_error(msg + " (line " + itoa(line) + ")");
2422
}
2523

2624
static void expect_argc(const AstNode& node, size_t count)

src/core/client.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ class Client {
3636

3737
private:
3838
Client::State state_;
39-
uint64_t id_;
4039
int fd_;
41-
sockaddr_in addr_;
4240
std::string send_buffer_;
4341
HttpParser parser_;
4442
Handler* handler_;

src/handler/static_file_handler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ static std::string resolve_path(const std::string& path,
4545
static const char* derive_file_type(const std::string& file_path)
4646
{
4747
size_t pos = file_path.rfind(".");
48+
4849
if (pos == std::string::npos)
4950
return ("application/octet-stream");
5051

5152
std::string ext = file_path.substr(pos + 1);
53+
5254
if (ext == "html" || ext == "htm")
5355
return "text/html; charset=UTF-8";
5456
if (ext == "txt")
@@ -150,4 +152,4 @@ void StaticFileHandler::set_error(const HttpResponse::Status code)
150152
{
151153
res_ = HttpResponse::make_error(code, rc_.shared.error_pages, req_);
152154
out_buf_ = res_.to_string();
153-
}
155+
}

src/http/http_response.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
HttpResponse::HttpResponse(HttpVersion protocol)
1515
: http_version(protocol),
1616
code(HttpResponse::kStatusOk),
17+
content_length(0),
1718
is_chunked(false),
1819
keep_alive(http_version == kHttpVersion1_1)
1920
{

src/util/itoa.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "util/string.hpp"
2+
13
#include <sstream>
24
#include <string>
35

tests/config_parser_unittest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ UTEST(ConfigParserTest, SingleStatement)
6767
std::vector<AstNode> nodes = parser.parse_tokens();
6868
ASSERT_EQ(1u, nodes.size());
6969

70-
const AstNode statement = nodes[0];
70+
const AstNode& statement = nodes[0];
7171
EXPECT_STREQ("listen", statement.name.c_str());
7272
ASSERT_EQ(1u, statement.args.size());
7373
EXPECT_STREQ("8080", statement.args[0].c_str());
@@ -86,7 +86,7 @@ UTEST(ConfigParserTest, SingleBlock)
8686
std::vector<AstNode> nodes = parser.parse_tokens();
8787
ASSERT_EQ(1u, nodes.size());
8888

89-
const AstNode block = nodes[0];
89+
const AstNode& block = nodes[0];
9090
EXPECT_STREQ("server", block.name.c_str());
9191
ASSERT_EQ(0u, block.args.size());
9292
ASSERT_EQ(0u, block.children.size());
@@ -108,13 +108,13 @@ UTEST(ConfigParserTest, NestedBlockAndStatement)
108108
std::vector<AstNode> nodes = parser.parse_tokens();
109109
ASSERT_EQ(1u, nodes.size());
110110

111-
const AstNode block = nodes[0];
111+
const AstNode& block = nodes[0];
112112
EXPECT_STREQ("server", block.name.c_str());
113113
ASSERT_EQ(0u, block.args.size());
114114
ASSERT_EQ(1u, block.children.size());
115115
EXPECT_EQ(1, block.line);
116116

117-
const AstNode statement = block.children[0];
117+
const AstNode& statement = block.children[0];
118118
EXPECT_STREQ("listen", statement.name.c_str());
119119
ASSERT_EQ(1u, statement.args.size());
120120
EXPECT_STREQ("8080", statement.args[0].c_str());

0 commit comments

Comments
 (0)