MCPcopy Create free account
hub / github.com/davisking/dlib / read_with_limit

Function read_with_limit

dlib/server/server_http.cpp:122–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120 }
121
122 void read_with_limit(
123 std::istream& in,
124 std::string& buffer,
125 int delim = '\n'
126 )
127 {
128 using namespace std;
129 const size_t max = 64*1024;
130 buffer.clear();
131 buffer.reserve(300);
132
133 while (in.peek() != delim && in.peek() != '\n' && in.peek() != EOF && buffer.size() < max)
134 {
135 buffer += (char)in.get();
136 }
137
138 // if we quit the loop because the data is longer than expected or we hit EOF
139 if (in.peek() == EOF)
140 throw http_parse_error("HTTP field from client terminated incorrectly", 414);
141 if (buffer.size() == max)
142 throw http_parse_error("HTTP field from client is too long", 414);
143
144 in.get();
145 // eat any remaining whitespace
146 if (delim == ' ')
147 {
148 while (in.peek() == ' ')
149 in.get();
150 }
151 }
152 }
153
154// ----------------------------------------------------------------------------------------

Callers 1

parse_http_requestFunction · 0.85

Calls 5

reserveMethod · 0.80
http_parse_errorClass · 0.70
clearMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected