| 1010 | } |
| 1011 | |
| 1012 | void HttpResponder::SendGCodeReply() noexcept |
| 1013 | { |
| 1014 | { |
| 1015 | // Do we need to keep the G-Code reply for other clients? |
| 1016 | bool clearReply = false; |
| 1017 | MutexLocker Lock(gcodeReplyMutex); |
| 1018 | |
| 1019 | if (!gcodeReply.IsEmpty()) |
| 1020 | { |
| 1021 | clientsServed++; |
| 1022 | if (clientsServed < numSessions) |
| 1023 | { |
| 1024 | // Yes - make sure the Network class doesn't discard its buffers yet |
| 1025 | // NB: This must happen here, because NetworkTransaction::Write() might already release OutputBuffers |
| 1026 | gcodeReply.IncreaseReferences(1); |
| 1027 | } |
| 1028 | else |
| 1029 | { |
| 1030 | // No - clean up again later |
| 1031 | clearReply = true; |
| 1032 | } |
| 1033 | |
| 1034 | if (reprap.Debug(Module::Webserver)) |
| 1035 | { |
| 1036 | GetPlatform().MessageF(UsbMessage, "Sending G-Code reply to HTTP client %d of %d (length %u)\n", clientsServed, numSessions, gcodeReply.DataLength()); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | // Send the whole G-Code reply as plain text to the client |
| 1041 | outBuf->copy( "HTTP/1.1 200 OK\r\n" |
| 1042 | "Cache-Control: no-cache, no-store, must-revalidate\r\n" |
| 1043 | "Pragma: no-cache\r\n" |
| 1044 | "Expires: 0\r\n" |
| 1045 | "Content-Type: text/plain\r\n" |
| 1046 | ); |
| 1047 | outBuf->catf("Content-Length: %u\r\n", gcodeReply.DataLength()); |
| 1048 | AddCorsHeader(); |
| 1049 | outBuf->cat("Connection: close\r\n\r\n"); |
| 1050 | outStack.Append(gcodeReply); |
| 1051 | |
| 1052 | // Possibly clean up the G-code reply once again |
| 1053 | if (clearReply) |
| 1054 | { |
| 1055 | gcodeReply.Clear(); |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | Commit(); |
| 1060 | } |
| 1061 | |
| 1062 | // Send a JSON response to the current command. outBuf is non-null on entry. |
| 1063 | void HttpResponder::SendJsonResponse(const char *_ecv_array command) noexcept |
nothing calls this directly
no test coverage detected