-
Notifications
You must be signed in to change notification settings - Fork 1
/
JsHttp.h
48 lines (40 loc) · 1.01 KB
/
JsHttp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef _JS_HTTP_H_
#define _JS_HTTP_H_
#include "libev/ev.h"
#include "http-parser/http_parser.h"
#include "JsObject.h"
#define MAX_URL_LENGTH 128
#define HTTP_BUFFER_SIZE 65535
class JsHttpRequest
{
private:
char buffer[HTTP_BUFFER_SIZE] = {0};
int buffer_index = 0;
public:
JsHttpRequest() {
callback = NULL;
}
~JsHttpRequest() {
if (callback != NULL) {
jerry_api_release_object(callback);
}
}
int sock;
ev_io watcher;
jerry_api_object_t* callback;
void CallBack(int status_code, const char* data);
void Read(int events);
int SendRequest(char* host, short port, char* data, jerry_api_object_t* function);
static int OnBodyCallback(http_parser* parser, const char *at, size_t length);
static void JsHttpReader(EV_P_ ev_io *w, int events);
static void ParseUrl(char* url, char* host, int* port, char* path);
};
class JsHttp : public JsObject
{
public:
JsHttp() : JsObject("Http") {
}
static bool METHOD(Get);
static void Register();
};
#endif