Server-Side Web Programming: The Request and Response Objects
Server-Side Web Programming: The Request and Response Objects
Web Programming
Lecture 15:
The Request and Response
Objects
Http Requests and Responses
• request object
– Properties of browser
– IP address and host name of referring machine
• request.getRemoteAddr()
• request.getHost()
• Not particularly useful for identification (too easy to fake)
• response object
– Can be used to tell browser more than just html page to display
– Format to display response page, etc.
Http Requests and Responses
Requests
• Contains information about browser that submitted request
• Main components:
– Referrer: Page from which request was submitted
– Accept: Preferred order of MIME types accepted by browser
– Accept-Encoding: Types of compression understood by
browser
• gzip, etc.
– Accept-Language: Language codes for accepted languages
• “en”, “en-us”, etc.
– User-Agent: Browser type
• Long string containing identifiers specific to browser
– “MSIE”, etc.
MIME Types
• Multipurpose Internet
Mail Extensions:
Formats for transmitting
data via email / internet
– Text formats
– Image formats
– Application formats
(programs browser can
run to display page)
– Audio and video
multimedia formats
– response.setContentType(“application/vnd.ms-excel”);
• Syntax:
response.setIntHeader(“refresh”, time in seconds);
• Example:
response.setIntHeader(“refresh”, 60);