Nikolay Kostov Telerik Corporation www.telerik.com.

Slides:



Advertisements
Similar presentations
1 Caching in HTTP Representation and Management of Data on the Internet.
Advertisements

HTTP – HyperText Transfer Protocol
Web basics HTTP – – URI/L/Ns – HTML –
1 HTTP – HyperText Transfer Protocol Part 1. 2 Common Protocols In order for two remote machines to “ understand ” each other they should –‘‘ speak the.
16-Jun-15 HTTP Hypertext Transfer Protocol. 2 HTTP messages HTTP is the language that web clients and web servers use to talk to each other HTTP is largely.
HTTP Hypertext Transfer Protocol. HTTP messages HTTP is the language that web clients and web servers use to talk to each other –HTTP is largely “under.
HTTP HyperText Transfer Protocol Part 2.
How the web works: HTTP and CGI explained
What’s a Web Cache? Why do people use them? Web cache location Web cache purpose There are two main reasons that Web cache are used:  to reduce latency.
Definitions, Definitions, Definitions Lead to Understanding.
1 K. Salah Module 2.1: Application Layer Application-level protocols provide high-level services –Web and HTTP –DNS –Electronic mail –Remote login –FTP.
HTTP HyperText Transfer Protocol Part 3.
HTTP Overview Vijayan Sugumaran School of Business Administration Oakland University.
2/9/2004 Web and HTTP February 9, /9/2004 Assignments Due – Reading and Warmup Work on Message of the Day.
Hypertext Transport Protocol CS Dick Steflik.
CSC 2720 Building Web Applications Servlet – Getting and Setting HTTP Headers.
 What is it ? What is it ?  URI,URN,URL URI,URN,URL  HTTP – methods HTTP – methods  HTTP Request Packets HTTP Request Packets  HTTP Request Headers.
Rensselaer Polytechnic Institute CSC-432 – Operating Systems David Goldschmidt, Ph.D.
1 Caching  Temporary storage of frequently accessed data (duplicating original data stored somewhere else)  Reduces access time/latency for clients 
Advanced Shell Programming. 2 Objectives Use techniques to ensure a script is employing the correct shell Set the default shell Configure Bash login and.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
COMP3016 Web Technologies Introduction and Discussion What is the Web?
Java Technology and Applications
SUNY Polytechnic Institute CS 490 – Web Design, AJAX, jQuery Web Services A web service is a software system that supports interaction (requesting data,
Krerk Piromsopa. Web Caching Krerk Piromsopa. Department of Computer Engineering. Chulalongkorn University.
HTTP Protocol Specification
Web Caching: Replication on the World Wide Web Jonathan Bulava CSC8530 – Distributed Systems Dr. Paul Schragger.
FTP (File Transfer Protocol) & Telnet
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
HTTP Reading: Section and COS 461: Computer Networks Spring
CSC 2720 Building Web Applications Getting and Setting HTTP Headers (With PHP Examples)
1 Lecture #7-8 HTTP – HyperText Transfer Protocol HAIT Summer 2005 Shimrit Tzur-David.
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
2: Application Layer1 CS 4244: Internet Software Development Dr. Eli Tilevich.
Rensselaer Polytechnic Institute Shivkumar Kalvanaraman, Biplab Sikdar 1 The Web: the http protocol http: hypertext transfer protocol Web’s application.
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
Maryam Elahi University of Calgary – CPSC 441.  HTTP stands for Hypertext Transfer Protocol.  Used to deliver virtually all files and other data (collectively.
WWW, HTTP, GET, POST, Cookies Svetlin Nakov Telerik Corporation
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Web Server Design Week 8 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 3/3/10.
HTTP1 Hypertext Transfer Protocol (HTTP) After this lecture, you should be able to:  Know how Web Browsers and Web Servers communicate via HTTP Protocol.
Web Server Design Week 4 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 2/03/10.
1 Caching in HTTP Representation and Management of Data on the Internet.
HTTP support for caching & replication. Conditional requests Server executes conditional request. Responds with a message body only if the condition is.
Date : 2/12/2010 Web Technology Solutions Class: Adding Security and Authentication Features to Your Application.
HTTP Protocol Design1 HTTP - timeline r Mar 1990 CERN labs document proposing Web r Jan 1992 HTTP/0.9 specification r Dec 1992 Proposal to add MIME to.
Appendix E: Overview of HTTP ©SoftMoore ConsultingSlide 1.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
CITA 310 Section 2 HTTP (Selected Topics from Textbook Chapter 6)
CIT 383: Administrative ScriptingSlide #1 CIT 383: Administrative Scripting HTTP.
Web Server Design Week 13 Old Dominion University Department of Computer Science CS 495/595 Spring 2010 Martin Klein 4/7/10.
HTTP Here, we examine the hypertext transfer protocol (http) – originally introduced around 1990 but not standardized until 1997 (version 1.0) – protocol.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
EE 122: Lecture 21 (HyperText Transfer Protocol - HTTP) Ion Stoica Nov 20, 2001 (*)
RESTful Web Services What is RESTful?
Overview of Servlets and JSP
COMP2322 Lab 2 HTTP Steven Lee Jan. 29, HTTP Hypertext Transfer Protocol Web’s application layer protocol Client/server model – Client (browser):
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 3 PHP Advanced.
Week 11: Application Layer 1 Web and HTTP r Web page consists of objects r Object can be HTML file, JPEG image, Java applet, audio file,… r Web page consists.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
© Janice Regan, CMPT 128, Jan 2007 CMPT 371 Data Communications and Networking HTTP 0.
CACHING TO IMPROVE PERFORMANCE
What’s Really Happening
JavaScript, AJAX and JSON MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/9/2016.
The Hypertext Transfer Protocol
HTTP request message: general format
Web Caching? Web Caching:.
Hypertext Transfer Protocol
EE 122: HyperText Transfer Protocol (HTTP)
Presentation transcript:

Nikolay Kostov Telerik Corporation

 HTTP headers  Output buffer control  Browser cache  Redirecting the browser

 Each HTTP request and response contains of headers and body  Headers describe the transferred data  Type  Length  Encoding  Etc.  PHP can modify the response headers  header function

 header($header, $replace, $response_code)  Adds or modifies HTTP header of the response  $header is string in the following form  Name: Value  $replace sets whether to replace existing similar header with the same name or add it  $response_code sets the HTTP response code (e.g. 302, 404, etc.)

 Redirect the Web browser  Set multiple headers with one name  Example: force browser to require HTTP authentication  Example: page inaccessible header ("Location: header ("WWW-Authenticate: Negotiate"); header ('WWW-Authenticate: Basic realm="Secure Area"', false); header ("WWW-Authenticate: Negotiate"); header ('WWW-Authenticate: Basic realm="Secure Area"', false); header ("HTTP/ Not Found"); // or maybe header ("HTTP/ Forbidden"); header ("HTTP/ Not Found"); // or maybe header ("HTTP/ Forbidden");

 Example: Page receives get parameter "down" that is some MP3 file ID in directory (MP3DIR constant)  This script will either send 404 error on request or will return the MP3 file for download $file = MP3DIR.$_GET['down'].".mp3"; if (!file_exists($file)) header ("HTTP/ Not Found",true,404); header ("HTTP/ Not Found",true,404); else { header ('Content-Type: audio/x-mp3'); header ('Content-Type: audio/x-mp3'); header ('Content-Length: '. header ('Content-Length: '.filesize($file)); header('Content-Disposition: attachment; '. 'filename='.$_GET['down'].'.mp3'); header('Content-Disposition: attachment; '. 'filename='.$_GET['down'].'.mp3'); echo file_get_contents($file); echo file_get_contents($file);} $file = MP3DIR.$_GET['down'].".mp3"; if (!file_exists($file)) header ("HTTP/ Not Found",true,404); header ("HTTP/ Not Found",true,404); else { header ('Content-Type: audio/x-mp3'); header ('Content-Type: audio/x-mp3'); header ('Content-Length: '. header ('Content-Length: '.filesize($file)); header('Content-Disposition: attachment; '. 'filename='.$_GET['down'].'.mp3'); header('Content-Disposition: attachment; '. 'filename='.$_GET['down'].'.mp3'); echo file_get_contents($file); echo file_get_contents($file);}

 Browser cache resources, downloaded over network  On next request they use the headers to detect if they should re-download or reuse the cached resource  Resources carry set of headers to control the browser caching  Expires header, Last-Modified, If-Modified-Since header  ETag, If-None-Match  Cache-Control

 HTTP Request Example:  HTTP Response Example: GET /index.html HTTP/1.0 User-Agent: Mozilla/5.0 From: something.somewhere.net Accept: text/html,text/plain,application/* Host: If-Modified-Since: Wed, 19 Oct :50:00 GMT GET /index.html HTTP/1.0 User-Agent: Mozilla/5.0 From: something.somewhere.net Accept: text/html,text/plain,application/* Host: If-Modified-Since: Wed, 19 Oct :50:00 GMT HTTP/ Not Modified Date: Fri, 31 Dec :59:59 GMT HTTP/ Not Modified Date: Fri, 31 Dec :59:59 GMT

 Server sends Last-Modified and Expires dates in response for the resource  Tells the browser how long the resource should be kept as current version  Both in GMT format  Browser sends If-Modified-Since header on each request with the date of the resource it has cached  If version is latest, server replies with "303 Not Modified" HTTP code

 ETag is unique identifier for the resource and its version  Sent by the server, stored by the browser  Browser sends on next request the ETag of the cached version  Sends the ETag in If-None-Match header  Newer approach  Most web servers send both Last-Modified and ETag headers

 Server can send Cache-Control header that instruct the browser cache engine  Value consists of comma separated name=value pairs or only names  max-age=seconds – sets maximum time that version should be considered fresh  s-maxage=seconds – same as max-age but applies to proxies  public – marks headers of response as cacheable

 no-cache – instructs revalidation to be required on next request  Usually performed as HEAD request  no-store – instructs not to store version of the resource under any circumstances  must-revalidate – tells cache engines they must obey and freshness information you give them  Some caches load older version under some circumstances  proxy-revalidate – similar to must-revalidate but applies to proxies

Disable Browser Cache - Example header('Cache-Control: no-cache'); header('Pragma: no-cache'); header("Expires: 0"); header('Cache-Control: no-cache'); header('Pragma: no-cache'); header("Expires: 0");

 The Web server (Apache) buffers the script output  Sends it automatically if there is enough data to send (buffer is full)  Buffer can be controlled  Multiple buffers can be defined and flushed, canceled or stored  Allows reordering of the output data  Example – first run script that generates page body, then print head  Example – first print output, then send headers

 Functions for buffer control are prefixed with ob_ in PHP  ob_start ($callback, $chunk, $erase) – starts new buffer  After this function is called no output is sent to the browser, except headers  Output buffers are stackable  Can call second ob_start while another is active

 All parameters are optional  $callback is function name to call when buffer is flushed  This function can modify the data to be sent  Receives one parameter – the data in the buffer  Must return string – the data to be sent  If $chunk is specified, buffer will flush if stored data reaches this size  Value of 0 means no automatic flush  Value of 1 sets $chunk to 4096  $erase sets whether the buffer should not be deleted until script ends

 ob_flush – sends the buffer content and erases all stored data  Keeps the buffer active  ob_end_flush – similar to ob_flush but destroys the buffer  ob_implicit_flush ($mode) – sets implicit flush on or off  $mode is optional boolean, defaults to true  With implicit flush, all writing to the buffer is automatically sent

 ob_get_contents – returns the content of the current buffer as string  Doesn't clear or stop the buffer  ob_get_clean – returns the buffer content and deletes it  ob_get_flush – returns the buffer content, flushes it and deletes it

 ob_clean – erases the data in the output buffer but does not delete the buffer  ob_end_clean – cleans the output buffer data and deletes the buffer  ob_end_flush – flushes the output buffer and deletes it

Questions?

Exercises Create pages login.php and main.php and implement the following logic:   The login.php displays login form (username/password)   If successfully authenticated, the user is redirected to the main.php   Otherwise an error message is shown and the login form is displayed again   If main.php is requested and the user is not logged in, it redirects to login.php   Implement also “Logout” functionality