Woopsa.HTTPResponse.SetHeader C# (CSharp) Method

SetHeader() public method

Sets the value of an HTTP Response Header. Many standard headers are defined in WebServer.HTTPHeader, but custom headers can always be manually set in case this is desired.

Headers are sent in the Header: Value format in the HTTP protocol.

public SetHeader ( string header, string value ) : void
header string /// The name of the header, for example: /// /// /// "My-Custom-Header" /// ///
value string /// The value of the header. ///
return void
        public void SetHeader(string header, string value)
        {
            _headers[header] = value;
        }

Usage Example

コード例 #1
0
        private void HandleRequest(WoopsaVerb verb, HTTPRequest request, HTTPResponse response)
        {
            try
            {
                // This is the first thing we do, that way even 404 errors have the right headers
                if (AllowCrossOrigin)
                {
                    // TODO: constantes symboliques
                    response.SetHeader("Access-Control-Allow-Origin", "*");
                }
                string result = null;
                ExecuteBeforeWoopsaModelAccess();
                try
                {
                    switch (verb)
                    {
                    case WoopsaVerb.Meta:
                        result = GetMetadata(request.Subroute);
                        break;

                    case WoopsaVerb.Read:
                        result = ReadValue(request.Subroute);
                        break;

                    case WoopsaVerb.Write:
                        result = WriteValue(request.Subroute, request.Body["value"]);
                        break;

                    case WoopsaVerb.Invoke:
                        result = InvokeMethod(request.Subroute, request.Body);
                        break;
                    }
                }
                finally
                {
                    ExecuteAfterWoopsaModelAccess();
                }
                response.SetHeader(HTTPHeader.ContentType, MIMETypes.Application.JSON);
                if (result != null)
                {
                    response.WriteString(result);
                }
            }
            catch (WoopsaNotFoundException e)
            {
                response.WriteError(HTTPStatusCode.NotFound, e.Message, WoopsaFormat.Serialize(e), MIMETypes.Application.JSON);
            }
            catch (WoopsaInvalidOperationException e)
            {
                response.WriteError(HTTPStatusCode.BadRequest, e.Message, WoopsaFormat.Serialize(e), MIMETypes.Application.JSON);
            }
            catch (WoopsaException e)
            {
                response.WriteError(HTTPStatusCode.InternalServerError, e.Message, WoopsaFormat.Serialize(e), MIMETypes.Application.JSON);
            }
            catch (Exception e)
            {
                response.WriteError(HTTPStatusCode.InternalServerError, e.Message, WoopsaFormat.Serialize(e), MIMETypes.Application.JSON);
            }
        }
All Usage Examples Of Woopsa.HTTPResponse::SetHeader