MCPcopy Create free account
hub / github.com/apache/impala / parseStatusLine

Method parseStatusLine

be/src/transport/THttpServer.cpp:218–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218bool THttpServer::parseStatusLine(char* status) {
219 char* method = status;
220 char* path = strchr(method, ' ');
221 if (path == NULL) {
222 throw TTransportException(string("Bad Status: ") + status);
223 }
224
225 *path = '\0';
226 while (*(++path) == ' ') {
227 };
228
229 char* http = strchr(path, ' ');
230 if (http == NULL) {
231 throw TTransportException(string("Bad Status: ") + status);
232 }
233 *http = '\0';
234
235 if (strcmp(method, "POST") == 0) {
236 // First time filling a field in wrapped_request_, so initialize
237 // it first. Should be only non-null in case of SAML authentication.
238 wrapped_request_ = callbacks_.init_wrapped_http_request_fn();
239 if (wrapped_request_) wrapped_request_->method = "POST";
240
241 string err_msg;
242 if (!callbacks_.path_fn(string(path), &err_msg, &readWholeBodyForAuth_)) {
243 throw TTransportException(err_msg);
244 }
245 // POST method ok, looking for content.
246 return true;
247 } else if (strcmp(method, "OPTIONS") == 0) {
248 // preflight OPTIONS method, we don't need further content.
249 // how to graciously close connection?
250 uint8_t* buf;
251 uint32_t len;
252 writeBuffer_.getBuffer(&buf, &len);
253
254 // Construct the HTTP header
255 std::ostringstream h;
256 h << "HTTP/1.1 200 OK" << CRLF << "Date: " << getTimeRFC1123() << CRLF
257 << "Access-Control-Allow-Origin: *" << CRLF << "Access-Control-Allow-Methods: POST, OPTIONS"
258 << CRLF << "Access-Control-Allow-Headers: Content-Type" << CRLF << CRLF;
259 string header = h.str();
260
261 // Write the header, then the data, then flush
262 transport_->write((const uint8_t*)header.c_str(), static_cast<uint32_t>(header.size()));
263 transport_->write(buf, len);
264 transport_->flush();
265
266 // Reset the buffer and header variables
267 writeBuffer_.resetBuffer();
268 readHeaders_ = true;
269 return true;
270 }
271 throw TTransportException(string("Bad Status (unsupported method): ") + status);
272}
273
274void THttpServer::headersDone() {
275 if (!header_x_request_id_.empty() || !header_x_session_id_.empty() ||

Callers

nothing calls this directly

Calls 4

strMethod · 0.45
writeMethod · 0.45
sizeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected