mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core: HttpRequest: WhenContent now only receives data of final OK content (not redirection or authorization texts or errors)
git-svn-id: svn://ultimatepp.org/upp/trunk@11249 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
718348298f
commit
5148266e5f
3 changed files with 27 additions and 16 deletions
|
|
@ -57,7 +57,7 @@ void HttpRequest::Init()
|
|||
redirect_count = 0;
|
||||
retry_count = 0;
|
||||
gzip = false;
|
||||
WhenContent = callback(this, &HttpRequest::ContentOut);
|
||||
all_content = false;
|
||||
WhenAuthenticate = callback(this, &HttpRequest::ResolveDigestAuthentication);
|
||||
chunk = 4096;
|
||||
timeout = 120000;
|
||||
|
|
@ -760,11 +760,6 @@ void HttpRequest::StartBody()
|
|||
}
|
||||
}
|
||||
|
||||
void HttpRequest::ContentOut(const void *ptr, int size)
|
||||
{
|
||||
body.Cat((const char *)ptr, size);
|
||||
}
|
||||
|
||||
void HttpRequest::Out(const void *ptr, int size)
|
||||
{
|
||||
LLOG("HTTP Out " << size);
|
||||
|
|
@ -775,7 +770,10 @@ void HttpRequest::Out(const void *ptr, int size)
|
|||
phase = FAILED;
|
||||
return;
|
||||
}
|
||||
WhenContent(ptr, size);
|
||||
if(WhenContent && (status_code >= 200 && status_code < 300 || all_content))
|
||||
WhenContent(ptr, size);
|
||||
else
|
||||
body.Cat((const char *)ptr, size);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -389,6 +389,7 @@ class HttpRequest : public TcpSocket {
|
|||
bool std_headers;
|
||||
bool hasurlvar;
|
||||
bool keep_alive;
|
||||
bool all_content;
|
||||
String contenttype;
|
||||
String username;
|
||||
String password;
|
||||
|
|
@ -438,7 +439,6 @@ class HttpRequest : public TcpSocket {
|
|||
void CopyCookies();
|
||||
|
||||
void HttpError(const char *s);
|
||||
void ContentOut(const void *ptr, int size);
|
||||
void Out(const void *ptr, int size);
|
||||
|
||||
String CalculateDigest(const String& authenticate) const;
|
||||
|
|
@ -467,6 +467,7 @@ public:
|
|||
HttpRequest& MaxRetries(int n) { max_retries = n; return *this; }
|
||||
HttpRequest& RequestTimeout(int ms) { timeout = ms; return *this; }
|
||||
HttpRequest& ChunkSize(int n) { chunk = n; return *this; }
|
||||
HttpRequest& AllContent(bool b = true) { all_content = b; return *this; }
|
||||
|
||||
HttpRequest& Method(int m, const char *custom_name = NULL);
|
||||
HttpRequest& GET() { return Method(METHOD_GET); }
|
||||
|
|
|
|||
|
|
@ -18,26 +18,32 @@ topic "HttpRequest";
|
|||
[s3;%% &]
|
||||
[ {{10000F(128)G(128)@1 [s0;%% [* Public Member List]]}}&]
|
||||
[s3; &]
|
||||
[s5;:HttpRequest`:`:WhenContent: [_^Callback2^ Callback2]<[@(0.0.255) const]_[@(0.0.255) vo
|
||||
id]_`*, [@(0.0.255) int]>_[* WhenContent]&]
|
||||
[s2;%% Defines consumer function for HTTP response content. Default
|
||||
value is method inside HttpRequest that gathers the output content
|
||||
in String that can be read using GetContent method.&]
|
||||
[s5;:HttpRequest`:`:WhenContent: [_^Callback2^ Event]<[@(0.0.255) const]_[@(0.0.255) void]_
|
||||
`*, [@(0.0.255) int]>_[* WhenContent]&]
|
||||
[s2;%% Defines consumer function for HTTP response content. If defined,
|
||||
HttpRequest uses this output event instead of storing the output
|
||||
content in String that can be read using GetContent method. Note
|
||||
that only `"valid`" content, defined as content in response with
|
||||
status code in the range 200 .. 299 is sent to WhenContent `-
|
||||
this avoids problems with multiple requests because of redirection
|
||||
or authorization. It is possible to change this behavior with
|
||||
AllContent `- in that case client code is likely to use WhenStart
|
||||
to separate responses to individual requests.&]
|
||||
[s3; &]
|
||||
[s4; &]
|
||||
[s5;:HttpRequest`:`:WhenStart: [_^Callback^ Callback]_[* WhenStart]&]
|
||||
[s5;:HttpRequest`:`:WhenStart: [_^Callback^ Event<>]_[* WhenStart]&]
|
||||
[s2;%% Invoked each time HttpRequest starts a new request attempt
|
||||
`- this includes redirections, authentization or retries on error.
|
||||
Gives chance to client software to restart processing, e.g. to
|
||||
delete partially downloaded file.&]
|
||||
[s3; &]
|
||||
[s4; &]
|
||||
[s5;:HttpRequest`:`:WhenDo: [_^Callback^ Callback]_[* WhenDo]&]
|
||||
[s5;:HttpRequest`:`:WhenDo: [_^Callback^ Event<>]_[* WhenDo]&]
|
||||
[s2;%% Invoked each time Do routine exits. Useful to show progres
|
||||
or allow abortions in GUI.&]
|
||||
[s3; &]
|
||||
[s4; &]
|
||||
[s5;:Upp`:`:HttpRequest`:`:WhenAuthenticate: [_^Upp`:`:Gate^ Gate]_[* WhenAuthenticate]&]
|
||||
[s5;:Upp`:`:HttpRequest`:`:WhenAuthenticate: [_^Upp`:`:Gate^ Gate<>]_[* WhenAuthenticate]&]
|
||||
[s2;%% Invoked when request returns 401 code (unauthorized). Callback
|
||||
should check returned headers and if possible, provide authorization
|
||||
header (through Authorization). In that case, it should return
|
||||
|
|
@ -83,6 +89,12 @@ ize]([@(0.0.255) int]_[*@3 n])&]
|
|||
(default is 4096). Returns `*this.&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:Upp`:`:HttpRequest`:`:AllContent`(bool`): [_^Upp`:`:HttpRequest^ HttpRequest][@(0.0.255) `&
|
||||
]_[* AllContent]([@(0.0.255) bool]_[*@3 b]_`=_[@(0.0.255) true])&]
|
||||
[s2;%% When active, WhenContent receives content from all responses,
|
||||
even if they are just redirection or authorization texts.&]
|
||||
[s3;%% &]
|
||||
[s4; &]
|
||||
[s5;:HttpRequest`:`:Method`(int`,const char`*`): [_^HttpRequest^ HttpRequest][@(0.0.255) `&
|
||||
]_[* Method]([@(0.0.255) int]_[*@3 m], [@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 custom`_na
|
||||
me]_`=_NULL)&]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue