David Fletcher
/
CC3000WebServer
A Port of TI's Webserver for the CC3000
WebServer/HttpResponse.h@0:6ad60d78b315, 2013-09-14 (annotated)
- Committer:
- dflet
- Date:
- Sat Sep 14 17:38:41 2013 +0000
- Revision:
- 0:6ad60d78b315
Mostly working will serve the default pages index.html and config.html, but config.html is not woring at present.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dflet | 0:6ad60d78b315 | 1 | /***************************************************************************** |
dflet | 0:6ad60d78b315 | 2 | * |
dflet | 0:6ad60d78b315 | 3 | * HttpResponse.h |
dflet | 0:6ad60d78b315 | 4 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ |
dflet | 0:6ad60d78b315 | 5 | * |
dflet | 0:6ad60d78b315 | 6 | * Redistribution and use in source and binary forms, with or without |
dflet | 0:6ad60d78b315 | 7 | * modification, are permitted provided that the following conditions |
dflet | 0:6ad60d78b315 | 8 | * are met: |
dflet | 0:6ad60d78b315 | 9 | * |
dflet | 0:6ad60d78b315 | 10 | * Redistributions of source code must retain the above copyright |
dflet | 0:6ad60d78b315 | 11 | * notice, this list of conditions and the following disclaimer. |
dflet | 0:6ad60d78b315 | 12 | * |
dflet | 0:6ad60d78b315 | 13 | * Redistributions in binary form must reproduce the above copyright |
dflet | 0:6ad60d78b315 | 14 | * notice, this list of conditions and the following disclaimer in the |
dflet | 0:6ad60d78b315 | 15 | * documentation and/or other materials provided with the |
dflet | 0:6ad60d78b315 | 16 | * distribution. |
dflet | 0:6ad60d78b315 | 17 | * |
dflet | 0:6ad60d78b315 | 18 | * Neither the name of Texas Instruments Incorporated nor the names of |
dflet | 0:6ad60d78b315 | 19 | * its contributors may be used to endorse or promote products derived |
dflet | 0:6ad60d78b315 | 20 | * from this software without specific prior written permission. |
dflet | 0:6ad60d78b315 | 21 | * |
dflet | 0:6ad60d78b315 | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
dflet | 0:6ad60d78b315 | 23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
dflet | 0:6ad60d78b315 | 24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
dflet | 0:6ad60d78b315 | 25 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
dflet | 0:6ad60d78b315 | 26 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
dflet | 0:6ad60d78b315 | 27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
dflet | 0:6ad60d78b315 | 28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
dflet | 0:6ad60d78b315 | 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
dflet | 0:6ad60d78b315 | 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
dflet | 0:6ad60d78b315 | 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
dflet | 0:6ad60d78b315 | 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
dflet | 0:6ad60d78b315 | 33 | * |
dflet | 0:6ad60d78b315 | 34 | *****************************************************************************/ |
dflet | 0:6ad60d78b315 | 35 | #ifndef _HTTP_RESPONSE_H_ |
dflet | 0:6ad60d78b315 | 36 | #define _HTTP_RESPONSE_H_ |
dflet | 0:6ad60d78b315 | 37 | |
dflet | 0:6ad60d78b315 | 38 | #include "Common.h" |
dflet | 0:6ad60d78b315 | 39 | #include "HttpString.h" |
dflet | 0:6ad60d78b315 | 40 | |
dflet | 0:6ad60d78b315 | 41 | /** |
dflet | 0:6ad60d78b315 | 42 | * @defgroup HttpResponse HTTP Response modules |
dflet | 0:6ad60d78b315 | 43 | * This module implements routines to allow content handler modules to build and send HTTP responses back to the client. |
dflet | 0:6ad60d78b315 | 44 | * There are two layers in this module: |
dflet | 0:6ad60d78b315 | 45 | * - The lower layer consists of HttpResponse_Headers() and HttpResponse_Content(). These routines allow the caller to specify all details of the response. |
dflet | 0:6ad60d78b315 | 46 | * - The higher layer consists of HttpResponse_Canned*(). These routines emit canned (pre-made) responses, such as redirects and errors, which are useful in many situations. |
dflet | 0:6ad60d78b315 | 47 | * |
dflet | 0:6ad60d78b315 | 48 | * @{ |
dflet | 0:6ad60d78b315 | 49 | */ |
dflet | 0:6ad60d78b315 | 50 | |
dflet | 0:6ad60d78b315 | 51 | /** |
dflet | 0:6ad60d78b315 | 52 | * @defgroup HttpStatus Supported HTTP status codes |
dflet | 0:6ad60d78b315 | 53 | * @{ |
dflet | 0:6ad60d78b315 | 54 | */ |
dflet | 0:6ad60d78b315 | 55 | #define HTTP_STATUS_OK 200 |
dflet | 0:6ad60d78b315 | 56 | #define HTTP_STATUS_REDIRECT_PERMANENT 301 |
dflet | 0:6ad60d78b315 | 57 | #define HTTP_STATUS_REDIRECT_TEMPORARY 302 |
dflet | 0:6ad60d78b315 | 58 | #define HTTP_STATUS_ERROR_UNAUTHORIZED 401 |
dflet | 0:6ad60d78b315 | 59 | #define HTTP_STATUS_ERROR_NOT_FOUND 404 |
dflet | 0:6ad60d78b315 | 60 | #define HTTP_STATUS_ERROR_NOT_ACCEPTED 406 |
dflet | 0:6ad60d78b315 | 61 | #define HTTP_STATUS_ERROR_INTERNAL 500 |
dflet | 0:6ad60d78b315 | 62 | |
dflet | 0:6ad60d78b315 | 63 | /// @} |
dflet | 0:6ad60d78b315 | 64 | |
dflet | 0:6ad60d78b315 | 65 | /// The response data is gzip-compressed. Implies the header Content-Encoding: gzip |
dflet | 0:6ad60d78b315 | 66 | #define HTTP_RESPONSE_FLAG_COMPRESSED (1 << 0) |
dflet | 0:6ad60d78b315 | 67 | |
dflet | 0:6ad60d78b315 | 68 | /** |
dflet | 0:6ad60d78b315 | 69 | * Respond with the specified HTTP status and headers |
dflet | 0:6ad60d78b315 | 70 | * @param uConnection The connection number, as it appears in the HttpRequest structure |
dflet | 0:6ad60d78b315 | 71 | * @param uHttpStatus The HTTP status number to response with. Must be one of HTTP_STATUS_* |
dflet | 0:6ad60d78b315 | 72 | * @param uFlags Flags which are manifested in the response headers. See HTTP_RESPONSE_FLAG_* |
dflet | 0:6ad60d78b315 | 73 | * @param uContentLength The total length of content which will be sent via HttpResponse_Content() |
dflet | 0:6ad60d78b315 | 74 | * @param contentType The content type string, or NULL to omit the content type |
dflet | 0:6ad60d78b315 | 75 | * @param location A string which will be used for the Location header, or NULL to omit the Location header |
dflet | 0:6ad60d78b315 | 76 | */ |
dflet | 0:6ad60d78b315 | 77 | void HttpResponse_Headers(uint16 uConnection, uint16 uHttpStatus, uint16 uFlags, uint32 uContentLength, struct HttpBlob contentType, struct HttpBlob location); |
dflet | 0:6ad60d78b315 | 78 | |
dflet | 0:6ad60d78b315 | 79 | /** |
dflet | 0:6ad60d78b315 | 80 | * Retrieves the pointer and size of the packet-send buffer |
dflet | 0:6ad60d78b315 | 81 | * This function should be called by content handlers that wish to use the already-allocated packet-send buffer in calls to HttpResponse_Content() |
dflet | 0:6ad60d78b315 | 82 | * @param[out] pPacketSendBuffer Returns the pointer and size of the packet-send buffer |
dflet | 0:6ad60d78b315 | 83 | */ |
dflet | 0:6ad60d78b315 | 84 | void HttpResponse_GetPacketSendBuffer(struct HttpBlob* pPacketSendBuffer); |
dflet | 0:6ad60d78b315 | 85 | |
dflet | 0:6ad60d78b315 | 86 | /** |
dflet | 0:6ad60d78b315 | 87 | * Send response content to the client. |
dflet | 0:6ad60d78b315 | 88 | * This function may be called more than once, until all the content is sent. |
dflet | 0:6ad60d78b315 | 89 | * @param uConnection The connection number, as it appears in the HttpRequest structure |
dflet | 0:6ad60d78b315 | 90 | * @param content Content blob to send to the client. |
dflet | 0:6ad60d78b315 | 91 | */ |
dflet | 0:6ad60d78b315 | 92 | void HttpResponse_Content(uint16 uConnection, struct HttpBlob content); |
dflet | 0:6ad60d78b315 | 93 | |
dflet | 0:6ad60d78b315 | 94 | /** |
dflet | 0:6ad60d78b315 | 95 | * Sends a canned response, with an HTTP redirect |
dflet | 0:6ad60d78b315 | 96 | * This function should be called *instead* of HttpResponse_Status(), HttpResponse_Headers() and HttpResponse_Content() |
dflet | 0:6ad60d78b315 | 97 | * @param uConnection The connection number, as it appears in the HttpRequest structure |
dflet | 0:6ad60d78b315 | 98 | * @param pLocation The redirect URL |
dflet | 0:6ad60d78b315 | 99 | * @param bPermanent zero for temporary redirect, nonzero for permanent redirect |
dflet | 0:6ad60d78b315 | 100 | */ |
dflet | 0:6ad60d78b315 | 101 | void HttpResponse_CannedRedirect(uint16 uConnection, struct HttpBlob location, uint16 bPermanent); |
dflet | 0:6ad60d78b315 | 102 | |
dflet | 0:6ad60d78b315 | 103 | /** |
dflet | 0:6ad60d78b315 | 104 | * Sends a canned response, with an error message |
dflet | 0:6ad60d78b315 | 105 | * This function should be called *instead* of HttpResponse_Status(), HttpResponse_Headers() and HttpResponse_Content() |
dflet | 0:6ad60d78b315 | 106 | * @param uConnection The connection number, as it appears in the HttpRequest structure |
dflet | 0:6ad60d78b315 | 107 | * @param uHttpStatus The HTTP error status. Must be one of HTTP_STATUS_ERROR_* |
dflet | 0:6ad60d78b315 | 108 | */ |
dflet | 0:6ad60d78b315 | 109 | void HttpResponse_CannedError(uint16 uConnection, uint16 uHttpStatus); |
dflet | 0:6ad60d78b315 | 110 | |
dflet | 0:6ad60d78b315 | 111 | /// @} |
dflet | 0:6ad60d78b315 | 112 | |
dflet | 0:6ad60d78b315 | 113 | #endif //_HTTP_RESPONSE_H_ |
dflet | 0:6ad60d78b315 | 114 |