Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
PostHandler Class Reference

#include <UrlHandler.h>

Inheritance diagram for PostHandler:
UrlHandler

Public Member Functions

bool canHandle (const char *method, const char *url) override
 
int handle (Request *request, MHD_Connection *connection, const char *url, const char *method, const char *upload_data, size_t *upload_data_size) override
 
- Public Member Functions inherited from UrlHandler
virtual ~UrlHandler ()
 
virtual bool canHandle (const char *method, const char *url)=0
 
virtual int handle (Request *request, MHD_Connection *connection, const char *url, const char *method, const char *upload_data, size_t *upload_data_size)=0
 

Detailed Description

Definition at line 84 of file UrlHandler.h.

Member Function Documentation

◆ canHandle()

bool PostHandler::canHandle ( const char *  method,
const char *  url 
)
overridevirtual

Implements UrlHandler.

Definition at line 30 of file PostHandler.cpp.

30 {
31 return 0 == strcmp(method, MHD_HTTP_METHOD_POST) &&
32 0 == strcmp(url, "/new");
33}

◆ handle()

int PostHandler::handle ( Request request,
MHD_Connection *  connection,
const char *  url,
const char *  method,
const char *  upload_data,
size_t *  upload_data_size 
)
overridevirtual

Implements UrlHandler.

Definition at line 35 of file PostHandler.cpp.

37 {
38 UploadContext* uc = request->fUploadContext;
39
40 // New connection
41 if (!uc) {
42 // TODO make this a method on request
43 uc = new UploadContext;
44 uc->connection = connection;
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 SendTemplate(MHD_Connection *connection, bool redirect, const char *redirectUrl)
Definition: Response.cpp:80
MHD_Connection * connection
Definition: Request.h:31
MHD_PostProcessor * fPostProcessor
Definition: Request.h:30

The documentation for this class was generated from the following files: