mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 10:12:45 +00:00 
			
		
		
		
	LibCore: Use URL in CHttpRequest
Now there's just CHttpRequest::set_url(URL), no need to specify the host, port and path manually anymore. Updated ChanViewer and Downloader for the API change.
This commit is contained in:
		
							parent
							
								
									fb636389d6
								
							
						
					
					
						commit
						ee83b1bcf4
					
				
					 6 changed files with 11 additions and 19 deletions
				
			
		|  | @ -19,8 +19,7 @@ BoardListModel::~BoardListModel() | ||||||
| void BoardListModel::update() | void BoardListModel::update() | ||||||
| { | { | ||||||
|     CHttpRequest request; |     CHttpRequest request; | ||||||
|     request.set_hostname("a.4cdn.org"); |     request.set_url("http://a.4cdn.org/boards.json"); | ||||||
|     request.set_path("/boards.json"); |  | ||||||
| 
 | 
 | ||||||
|     auto* job = request.schedule(); |     auto* job = request.schedule(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -27,8 +27,7 @@ void ThreadCatalogModel::set_board(const String& board) | ||||||
| void ThreadCatalogModel::update() | void ThreadCatalogModel::update() | ||||||
| { | { | ||||||
|     CHttpRequest request; |     CHttpRequest request; | ||||||
|     request.set_hostname("a.4cdn.org"); |     request.set_url(String::format("http://a.4cdn.org/%s/catalog.json", m_board.characters())); | ||||||
|     request.set_path(String::format("/%s/catalog.json", m_board.characters())); |  | ||||||
| 
 | 
 | ||||||
|     auto* job = request.schedule(); |     auto* job = request.schedule(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -9,8 +9,7 @@ int main(int argc, char** argv) | ||||||
|     GApplication app(argc, argv); |     GApplication app(argc, argv); | ||||||
| 
 | 
 | ||||||
|     CHttpRequest request; |     CHttpRequest request; | ||||||
|     request.set_hostname("www.google.com"); |     request.set_url("http://www.google.com/"); | ||||||
|     request.set_path("/"); |  | ||||||
| 
 | 
 | ||||||
|     auto job = request.schedule(); |     auto job = request.schedule(); | ||||||
|     job->on_finish = [&job](bool success) { |     job->on_finish = [&job](bool success) { | ||||||
|  |  | ||||||
|  | @ -121,7 +121,7 @@ void CHttpJob::start() | ||||||
|         dbg() << "CHttpJob: on_connected callback"; |         dbg() << "CHttpJob: on_connected callback"; | ||||||
|         on_socket_connected(); |         on_socket_connected(); | ||||||
|     }; |     }; | ||||||
|     bool success = m_socket->connect(m_request.hostname(), m_request.port()); |     bool success = m_socket->connect(m_request.url().host(), m_request.url().port()); | ||||||
|     if (!success) |     if (!success) | ||||||
|         return did_fail(CNetworkJob::Error::ConnectionFailed); |         return did_fail(CNetworkJob::Error::ConnectionFailed); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -36,9 +36,9 @@ ByteBuffer CHttpRequest::to_raw_request() const | ||||||
|     StringBuilder builder; |     StringBuilder builder; | ||||||
|     builder.append(method_name()); |     builder.append(method_name()); | ||||||
|     builder.append(' '); |     builder.append(' '); | ||||||
|     builder.append(m_path); |     builder.append(m_url.path()); | ||||||
|     builder.append(" HTTP/1.0\r\nHost: "); |     builder.append(" HTTP/1.0\r\nHost: "); | ||||||
|     builder.append(m_hostname); |     builder.append(m_url.host()); | ||||||
|     builder.append("\r\n\r\n"); |     builder.append("\r\n\r\n"); | ||||||
|     return builder.to_byte_buffer(); |     return builder.to_byte_buffer(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #include <AK/AKString.h> | #include <AK/AKString.h> | ||||||
|  | #include <AK/URL.h> | ||||||
| 
 | 
 | ||||||
| class CNetworkJob; | class CNetworkJob; | ||||||
| 
 | 
 | ||||||
|  | @ -16,14 +17,10 @@ public: | ||||||
|     CHttpRequest(); |     CHttpRequest(); | ||||||
|     ~CHttpRequest(); |     ~CHttpRequest(); | ||||||
| 
 | 
 | ||||||
|     String hostname() const { return m_hostname; } |     const URL& url() const { return m_url; } | ||||||
|     int port() const { return m_port; } |     void set_url(const URL& url) { m_url = url; } | ||||||
|     String path() const { return m_path; } |  | ||||||
|     Method method() const { return m_method; } |  | ||||||
| 
 | 
 | ||||||
|     void set_hostname(const String& hostname) { m_hostname = hostname; } |     Method method() const { return m_method; } | ||||||
|     void set_port(int port) { m_port = port; } |  | ||||||
|     void set_path(const String& path) { m_path = path; } |  | ||||||
|     void set_method(Method method) { m_method = method; } |     void set_method(Method method) { m_method = method; } | ||||||
| 
 | 
 | ||||||
|     String method_name() const; |     String method_name() const; | ||||||
|  | @ -32,8 +29,6 @@ public: | ||||||
|     CNetworkJob* schedule(); |     CNetworkJob* schedule(); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     String m_hostname; |     URL m_url; | ||||||
|     String m_path; |  | ||||||
|     int m_port { 80 }; |  | ||||||
|     Method m_method { GET }; |     Method m_method { GET }; | ||||||
| }; | }; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling