Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » HttpRequest ignores server errors
HttpRequest ignores server errors [message #48739] Wed, 06 September 2017 13:24 Go to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
Hi,

I made some simple test and it appears that HttpRequest likes to ignore error code returned by http server.
Simple example:
	HttpRequest conn("http://google.com/nonexistingpage");
	conn.Trace(true);
	Value resp = conn.Execute();
	RDUMP(conn.IsFailure());
	RDUMP(conn.GetStatusCode());
	RDUMP(conn.GetErrorDesc());
	RDUMP(conn.IsError());
	RDUMP(resp.IsError());


and trace:
06.09.2017 13:11:14 HTTP START
06.09.2017 13:11:14 Using google.com:80
06.09.2017 13:11:14 Starting status 2 'Resolving host name', url: google.com
06.09.2017 13:11:14 HTTP Execute: Resolving host name
06.09.2017 13:11:14 HTTP StartConnect
06.09.2017 13:11:14 HTTP AfterConnect
06.09.2017 13:11:14 Starting status 6 'Sending request', url: google.com
06.09.2017 13:11:14 HTTP REQUEST google.com:0
06.09.2017 13:11:14 HTTP request:
06.09.2017 13:11:14 GET /nonexistingpage HTTP/1.1
06.09.2017 13:11:14 URL: http://google.com/nonexistingpage
06.09.2017 13:11:14 Host: google.com
06.09.2017 13:11:14 Connection: close
06.09.2017 13:11:14 Accept: */*
06.09.2017 13:11:14 Accept-Encoding: gzip
06.09.2017 13:11:14 User-Agent: U++ HTTP request
06.09.2017 13:11:14 
06.09.2017 13:11:14 HTTP request body:
06.09.2017 13:11:14 
06.09.2017 13:11:14 HTTP Execute: Sending request
06.09.2017 13:11:14 Starting status 7 'Receiving header', url: google.com
06.09.2017 13:11:14 HTTP Execute: Receiving header
06.09.2017 13:11:14 HTTP Header received: 
06.09.2017 13:11:14 HTTP/1.1 404 Not Found
06.09.2017 13:11:14 Content-Type: text/html; charset=UTF-8
06.09.2017 13:11:14 Referrer-Policy: no-referrer
06.09.2017 13:11:14 Content-Length: 1576
06.09.2017 13:11:14 Date: Wed, 06 Sep 2017 11:11:14 GMT
06.09.2017 13:11:14 Connection: close
06.09.2017 13:11:14 
06.09.2017 13:11:14 
06.09.2017 13:11:14 HTTP status code: 404
06.09.2017 13:11:14 Starting status 8 'Receiving content', url: google.com
06.09.2017 13:11:14 HTTP Execute: Receiving content
06.09.2017 13:11:14 HTTP reading body 1576
06.09.2017 13:11:14 HTTP Out 1576
06.09.2017 13:11:14 conn.IsFailure() = false
06.09.2017 13:11:14 conn.GetStatusCode() = 404
06.09.2017 13:11:14 conn.GetErrorDesc() = 
06.09.2017 13:11:14 conn.IsError() = false
06.09.2017 13:11:14 resp.IsError() = false


As you can see server returned code 404, but IsFailure(), IsError(), GetErrorDesc() ignored it.
At least IsFailure() should return true if code is not 2xx, according to the docs.
How about IsHttpError, IsError, GetErrorDesc?
Re: HttpRequest ignores server errors [message #48742 is a reply to message #48739] Fri, 08 September 2017 08:14 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, there are 3 levels that application can be interested in:

Socket error - IsSocketError
HTTP protocol error - IsFailure
Server returns 2xx response - IsSuccess

So what you are getting is inline with expectations.

Also note that Execute returns String (not Value, so IsError does not make sense), but if !IsSuccess(), returns String::Void().
Re: HttpRequest ignores server errors [message #48743 is a reply to message #48742] Fri, 08 September 2017 08:51 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
According to the docs:
bool IsFailure() const
Request has failed (it can be either due to connection errors or because the request did not ended with 2xx response code).


Return code was 404 and IsFailure() returned false, so at least in this case there is something wrong.

I've added IsSuccess() to the dump:
08.09.2017 06:49:08 HTTP status code: 404
08.09.2017 06:49:08 Starting status 8 'Receiving content', url: google.com
08.09.2017 06:49:08 HTTP Execute: Receiving content
08.09.2017 06:49:08 HTTP reading body 1576
08.09.2017 06:49:08 HTTP Out 1576
08.09.2017 06:49:08 conn.IsFailure() = false
08.09.2017 06:49:08 conn.IsSuccess() = false
08.09.2017 06:49:08 conn.GetStatusCode() = 404
08.09.2017 06:49:08 conn.GetErrorDesc() = 
08.09.2017 06:49:08 conn.IsError() = false

Re: HttpRequest ignores server errors [message #48744 is a reply to message #48743] Fri, 08 September 2017 09:45 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Sorry, that appears to be a documentation problem. Fixing.
Previous Topic: Code before Thread.Run() nor executed
Next Topic: how to broadcast in AsyncWebSocket?
Goto Forum:
  


Current Time: Thu Mar 28 13:45:31 CET 2024

Total time taken to generate the page: 0.01381 seconds