-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathJavascriptHttpRequest.h
More file actions
179 lines (152 loc) · 4.59 KB
/
JavascriptHttpRequest.h
File metadata and controls
179 lines (152 loc) · 4.59 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#pragma once
#include "JavascriptHttpRequest.generated.h"
UENUM()
namespace EJavascriptHttpRequestStatus
{
/**
* Enumerates the current state of an Http request
*/
enum Type
{
/** Has not been started via ProcessRequest() */
NotStarted,
/** Currently being ticked and processed */
Processing,
/** Finished but failed */
Failed,
/** Finished and was successful */
Succeeded
};
}
/**
*
*/
UCLASS()
class JAVASCRIPTHTTP_API UJavascriptHttpRequest : public UObject
{
GENERATED_UCLASS_BODY()
private:
bool IsProcessing;
public:
TSharedPtr<IHttpRequest> Request;
/**
* Gets the verb (GET, PUT, POST) used by the request.
*
* @return the verb string
*/
UFUNCTION(BlueprintCallable, Category = "Online | Http")
FString GetVerb();
/**
* Sets the verb used by the request.
* Eg. (GET, PUT, POST)
* Should be set before calling ProcessRequest.
* If not specified then a GET is assumed.
*
* @param Verb - verb to use.
*/
UFUNCTION(BlueprintCallable, Category = "Online | Http")
void SetVerb(const FString& Verb);
/**
* Sets the URL for the request
* Eg. (http://my.domain.com/something.ext?key=value&key2=value).
* Must be set before calling ProcessRequest.
*
* @param URL - URL to use.
*/
UFUNCTION(BlueprintCallable, Category = "Online | Http")
void SetURL(const FString& URL);
/**
* Sets the content of the request (optional data).
* Usually only set for POST requests.
*
* @param ContentPayload - payload to set.
*/
UFUNCTION(BlueprintCallable, Category = "Online | Http")
void SetContentFromMemory();
/**
* Sets the content of the request as a string encoded as UTF8.
*
* @param ContentString - payload to set.
*/
UFUNCTION(BlueprintCallable, Category = "Online | Http")
void SetContentAsString(const FString& ContentString);
/**
* Sets optional header info.
* Content-Length is the only header set for you.
* Required headers depends on the request itself.
* Eg. "multipart/form-data" needed for a form post
*
* @param HeaderName - Name of the header (ie, Content-Type)
* @param HeaderValue - Value of the header
*/
UFUNCTION(BlueprintCallable, Category = "Online | Http")
void SetHeader(const FString& HeaderName, const FString& HeaderValue);
/**
* Called to begin processing the request.
* OnProcessRequestComplete delegate is always called when the request completes or on error if it is bound.
* A request can be re-used but not while still being processed.
*
* @return if the request was successfully started.
*/
UFUNCTION(BlueprintCallable, Category = "Online | Http")
bool ProcessRequest();
/**
* Delegate called when an Http request completes
*
* @param first parameter - indicates whether or not the request was able to connect successfully
*/
DECLARE_DYNAMIC_DELEGATE_OneParam(FJavascriptHttpRequestCompleteDelegate, bool, successful);
/**
* Delegate called per tick to update an Http request upload or download size progress
*
* @param first parameter - the number of bytes sent / uploaded in the request so far.
* @param second parameter - the number of bytes received / downloaded in the response so far.
*/
DECLARE_DYNAMIC_DELEGATE_TwoParams(FJavascriptHttpRequestProgressDelegate, int32, sent, int32, recv);
UPROPERTY()
FJavascriptHttpRequestCompleteDelegate OnComplete;
UPROPERTY()
FJavascriptHttpRequestProgressDelegate OnProgress;
/**
* Called to cancel a request that is still being processed
*/
UFUNCTION(BlueprintCallable, Category = "Online | Http")
void CancelRequest();
/**
* Get the current status of the request being processed
*
* @return the current status
*/
UFUNCTION(BlueprintCallable, Category = "Online | Http")
EJavascriptHttpRequestStatus::Type GetStatus();
/**
* Gets the response code returned by the requested server.
* See EHttpResponseCodes for known response codes
*
* @return the response code.
*/
UFUNCTION(BlueprintCallable, Category = "Online | Http")
int32 GetResponseCode();
/**
* Returns the payload as a string, assuming the payload is UTF8.
*
* @return the payload as a string.
*/
UFUNCTION(BlueprintCallable, Category = "Online | Http")
FString GetContentAsString();
UFUNCTION(BlueprintCallable, Category = "Online | Http")
int32 GetContentLength();
UFUNCTION(BlueprintCallable, Category = "Online | Http")
void GetContentToMemory();
/**
* Gets the time that it took for the server to fully respond to the request.
*
* @return elapsed time in seconds.
*/
UFUNCTION(BlueprintCallable, Category = "Online | Http")
float GetElapsedTime();
virtual void BeginDestroy() override;
bool GetIsProcessing() const { return IsProcessing; }
void BeginProcessing();
void EndProcessing();
};