Flutter Engine
The Flutter Engine
PostHandler.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
10#include "microhttpd.h"
13
14using namespace Response;
15
16static const size_t kBufferSize = 1024;
17
18static int process_upload_data(void* cls, enum MHD_ValueKind kind,
19 const char* key, const char* filename,
20 const char* content_type, const char* transfer_encoding,
21 const char* data, uint64_t off, size_t size) {
22 struct UploadContext* uc = reinterpret_cast<UploadContext*>(cls);
23
24 if (0 != size) {
25 uc->fStream.write(data, size);
26 }
27 return MHD_YES;
28}
29
30bool PostHandler::canHandle(const char* method, const char* url) {
31 return 0 == strcmp(method, MHD_HTTP_METHOD_POST) &&
32 0 == strcmp(url, "/new");
33}
34
35int PostHandler::handle(Request* request, MHD_Connection* connection,
36 const char* url, const char* method,
37 const char* upload_data, size_t* upload_data_size) {
38 UploadContext* uc = request->fUploadContext;
39
40 // New connection
41 if (!uc) {
42 // TODO make this a method on request
43 uc = new UploadContext;
45 uc->fPostProcessor = MHD_create_post_processor(connection, kBufferSize,
48
49 request->fUploadContext = uc;
50 return MHD_YES;
51 }
52
53 // in process upload
54 if (0 != *upload_data_size) {
56 MHD_post_process(uc->fPostProcessor, upload_data, *upload_data_size);
57 *upload_data_size = 0;
58 return MHD_YES;
59 }
60
61 // end of upload
62 MHD_destroy_post_processor(uc->fPostProcessor);
63 uc->fPostProcessor = nullptr;
64
65 std::unique_ptr<SkStreamAsset> stream(request->fUploadContext->fStream.detachAsStream());
66 if (!request->initPictureFromStream(stream.get())) {
67 fprintf(stderr, "Could not create picture from stream.\n");
68 return MHD_NO;
69 }
70
71 // clear upload context
72 delete request->fUploadContext;
73 request->fUploadContext = nullptr;
74
75 return SendTemplate(connection, true, "/");
76}
static int process_upload_data(void *cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size)
Definition: PostHandler.cpp:18
static const size_t kBufferSize
Definition: PostHandler.cpp:16
#define SkASSERT(cond)
Definition: SkAssert.h:116
int handle(Request *request, MHD_Connection *connection, const char *url, const char *method, const char *upload_data, size_t *upload_data_size) override
Definition: PostHandler.cpp:35
bool canHandle(const char *method, const char *url) override
Definition: PostHandler.cpp:30
bool write(const void *buffer, size_t size) override
Definition: SkStream.cpp:535
int SendTemplate(MHD_Connection *connection, bool redirect, const char *redirectUrl)
Definition: Response.cpp:80
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SkDynamicMemoryWStream fStream
Definition: Request.h:29
MHD_Connection * connection
Definition: Request.h:31
MHD_PostProcessor * fPostProcessor
Definition: Request.h:30
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63