VIBE v5.1.6
Search Engine
Loading...
Searching...
No Matches
edu.usfca.cs272.HttpsFetcher Class Reference

Static Public Member Functions

static Map< String, List< String > > fetch (URI uri) throws IOException
 
static Socket openConnection (URI uri) throws UnknownHostException, IOException
 
static void printGetRequest (PrintWriter writer, URI uri) throws IOException
 
static Map< String, List< String > > processHttpHeaders (BufferedReader response) throws IOException
 
static Map< String, List< String > > fetch (String uri) throws URISyntaxException, IOException
 

Detailed Description

Demonstrates how to use the built-in HttpClient to fetch the headers and content from a URI on the web, as well as how to setup the Socket connections to do the same manually (well suited for web crawling).

Author
CS 272 Software Development (University of San Francisco)
Version
Spring 2024

Member Function Documentation

◆ fetch() [1/2]

static Map< String, List< String > > edu.usfca.cs272.HttpsFetcher.fetch ( String uri) throws URISyntaxException, IOException
static

See fetch(URI) for details.

Parameters
urithe URI to fetch
Returns
a map with the headers and content
Exceptions
URISyntaxExceptionif unable to convert String to URI
IOExceptionif unable to fetch headers and content
See also
#fetch(URI)

◆ fetch() [2/2]

static Map< String, List< String > > edu.usfca.cs272.HttpsFetcher.fetch ( URI uri) throws IOException
static

Fetches the headers and content for the specified URI. The content is placed as a list of all the lines fetched under the "Content" key.

Parameters
urithe URI to fetch
Returns
a map with the headers and content
Exceptions
IOExceptionif unable to fetch headers and content
See also
#openConnection(URI)
#printGetRequest(PrintWriter, URI)
#processHttpHeaders(BufferedReader)

◆ openConnection()

static Socket edu.usfca.cs272.HttpsFetcher.openConnection ( URI uri) throws UnknownHostException, IOException
static

Uses a Socket to open a connection to the web server associated with the provided URI. Supports HTTP and HTTPS connections.

Parameters
urithe URI to connect
Returns
a socket connection for that URI
Exceptions
UnknownHostExceptionif the host is not known
IOExceptionif an I/O error occurs when creating the socket
See also
URL::openConnection()
URLConnection
HttpURLConnection

◆ printGetRequest()

static void edu.usfca.cs272.HttpsFetcher.printGetRequest ( PrintWriter writer,
URI uri ) throws IOException
static

Writes a simple HTTP v1.1 GET request to the provided socket writer.

Parameters
writera writer created from a socket connection
urithe URI to fetch via the socket connection
Exceptions
IOExceptionif unable to write request to socket
See also
Builder::GET()

◆ processHttpHeaders()

static Map< String, List< String > > edu.usfca.cs272.HttpsFetcher.processHttpHeaders ( BufferedReader response) throws IOException
static

Gets the header fields from a reader associated with a socket connection. Requires that the socket reader has not yet been used, otherwise this method will return unpredictable results.

Parameters
responsea reader created from a socket connection
Returns
a map of header fields to a list of header values
Exceptions
IOExceptionif unable to read from socket
See also
URLConnection::getHeaderFields()
HttpHeaders::map()

The documentation for this class was generated from the following file: