Add Generic HTTP Request Class. Generalized HTTP Parsing.
authorjocelyn.turcotte@nokia.com <jocelyn.turcotte@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Apr 2012 13:23:23 +0000 (13:23 +0000)
committerjocelyn.turcotte@nokia.com <jocelyn.turcotte@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Apr 2012 13:23:23 +0000 (13:23 +0000)
commit008b4913bf0fecf13b569d483727b9c0f8b5647f
tree78bf3619c45385273abe4eb55f95ceebc7f9081f
parent369fca9949c13f5e9afcdd2ab1fce4534e50c689
Add Generic HTTP Request Class. Generalized HTTP Parsing.
https://bugs.webkit.org/show_bug.cgi?id=73092

Reviewed by Simon Hausmann.

A WebSocket server will need to read HTTP Requests before upgrading
to WebSocket framing. This patch creates a cross-platform HTTPRequest
class. Since some of this was already done in WebSocket code:

  - the header parsing code was extracted and put into HTTPParsers.cpp
  - WebSocketHandshakeRequest subclasses HTTPRequest
  - WebSocket code was refactored for these changes

Refactoring is covered by existing http/tests/websocket tests.

* CMakeLists.txt:
* GNUmakefile.list.am:

* Modules/websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::didOpenSocketStream):

  Extract the HTTP Header parsing out of WebSocketHandshake and
  put it into HTTP Parsers. Now make use of the generic parsing.

* Modules/websockets/WebSocketHandshake.cpp:
(WebCore):
(WebCore::trimInputSample):
(WebCore::WebSocketHandshake::clientHandshakeRequest): switch to RefCounted HandshakeRequest.
(WebCore::WebSocketHandshake::readStatusLine):
(WebCore::WebSocketHandshake::readHTTPHeaders): use generic HTTPParsers parsing.
* Modules/websockets/WebSocketHandshake.h: switch to RefCounted HandshakeRequest.

  WebSocketHandshakeRequest is a specialization of an HTTPRequest.
  Much of its original code was abstracted into HTTPRequest, and
  this is now a subclass with WebSocket key information.

* Modules/websockets/WebSocketHandshakeRequest.cpp:
(WebCore::WebSocketHandshakeRequest::WebSocketHandshakeRequest): initialize now calls super.
* Modules/websockets/WebSocketHandshakeRequest.h:
(WebCore::WebSocketHandshakeRequest::create): switch to being ref counted like HTTPRequest.
(WebSocketHandshakeRequest):

* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:

  Add generic HTTP Request parsing functions to HTTPParsers.cpp.
  Use out parameters to get values after parsing.

* platform/network/HTTPParsers.cpp:
(WebCore):
(WebCore::trimInputSample): taken from WebSocket parsing.
(WebCore::parseHTTPRequestLine): new code, parse a request line.
(WebCore::parseHTTPHeaders): taken from previous WebSocket parsing. Algorithm unchanged.
(WebCore::parseHTTPRequestBody): new code, just copy the date into the provided buffer.
* platform/network/HTTPParsers.h:
(WebCore):

  This adds a general HTTPRequest class. Accessors for the
  request method, url, httpVersion, headers, and data. You can
  create an HTTPRequest using the constructor, or parse one
  from a data buffer, such as one read from a socket.

* platform/network/HTTPRequest.cpp: Added.
(WebCore):
(WebCore::HTTPRequest::parseHTTPRequestFromBuffer): create an HTTPRequest by parsing data in a buffer.
(WebCore::HTTPRequest::parseRequestLine): helper to initialize members while parsing.
(WebCore::HTTPRequest::parseHeaders): helper to initialize members while parsing.
(WebCore::HTTPRequest::parseRequestBody): helper to initialize members while parsing.
(WebCore::HTTPRequest::HTTPRequest):
(WebCore::HTTPRequest::~HTTPRequest):
* platform/network/HTTPRequest.h: Added.
(WebCore):
(HTTPRequest):
(WebCore::HTTPRequest::create): create an empty request, or specify details.
(WebCore::HTTPRequest::requestMethod):
(WebCore::HTTPRequest::setRequestMethod):
(WebCore::HTTPRequest::url):
(WebCore::HTTPRequest::setURL):
(WebCore::HTTPRequest::body):
(WebCore::HTTPRequest::headerFields):
(WebCore::HTTPRequest::addHeaderField):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@113024 268f45cc-cd09-0410-ab3c-d52691b4dbfc
16 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Modules/websockets/WebSocketChannel.cpp
Source/WebCore/Modules/websockets/WebSocketHandshake.cpp
Source/WebCore/Modules/websockets/WebSocketHandshake.h
Source/WebCore/Modules/websockets/WebSocketHandshakeRequest.cpp
Source/WebCore/Modules/websockets/WebSocketHandshakeRequest.h
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/network/HTTPParsers.cpp
Source/WebCore/platform/network/HTTPParsers.h
Source/WebCore/platform/network/HTTPRequest.cpp [new file with mode: 0644]
Source/WebCore/platform/network/HTTPRequest.h [new file with mode: 0644]