Re: [PATCH] Reason pharses into the HTTP response

Alexander Malysh <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Organization Centrium GmbH
Message-ID <[email protected]>
Hi,

I'm in general +1 for such patch, but...
Please get rid of octstr_imm(...), because it's very very slow!

Just do for example:
+const char *http_reason_phrase(int status)
+{
+	switch (status) {
+	case HTTP_OK:
+		return "OK";						/* 200 */
...
+     }
+     return "Foo"; /* that's our default when status code not handled */
+}

Thanks in advance!

On Thursday 03 June 2004 12:59, Zoltán Dudás wrote:
> Hi All,
>
> Thanks for your comments. I modified the patch and I am testing it.
> There is the modified version but I didn't test it, yet.
>
> Dod
>
> Index: gateway/gwlib/http.c
> ===================================================================
> RCS file: /home/cvs/gateway/gwlib/http.c,v
> retrieving revision 1.217
> diff -u -r1.217 http.c
> --- gateway/gwlib/http.c	16 Feb 2004 19:41:26 -0000	1.217
> +++ gateway/gwlib/http.c	3 Jun 2004 10:43:49 -0000
> @@ -2338,6 +2338,81 @@
>      return client;
>  }
>
> +/*
> + * The http_send_reply(...) uses this function to determinate the
> + * reason pahrase for a status code.
> + */
> +Octstr *http_reason_phrase(int status)
> +{
> +	Octstr *result=0;
> +	switch (status) {
> +	case HTTP_OK:
> +		result= octstr_imm("OK");						/* 200 */
> +		break;
> +	case HTTP_CREATED:
> +		result= octstr_imm("Created");					/* 201 */
> +		break;
> +	case HTTP_ACCEPTED:
> +		result= octstr_imm("Accepted");					/* 202 */
> +		break;
> +	case HTTP_NO_CONTENT:
> +		result= octstr_imm("No Content");				/* 204 */
> +		break;
> +	case HTTP_RESET_CONTENT:
> +		result= octstr_imm("Reset Content");			/* 205 */
> +		break;
> +	case HTTP_MOVED_PERMANENTLY:
> +		result= octstr_imm("Moved Permanently"); 		/* 301 */
> +		break;
> +	case HTTP_FOUND:
> +		result= octstr_imm("Found");					/* 302 */
> +		break;
> +	case HTTP_SEE_OTHER:
> +		result= octstr_imm("See Other");				/* 303 */
> +		break;
> +	case HTTP_NOT_MODIFIED:
> +		result= octstr_imm("Not Modified");				/* 304 */
> +		break;
> +	case HTTP_TEMPORARY_REDIRECT:
> +		result= octstr_imm("Temporary Redirect");		/* 307 */
> +		break;
> +	case HTTP_BAD_REQUEST:
> +		result= octstr_imm("Bad Request");				/* 400 */
> +		break;
> +	case HTTP_UNAUTHORIZED:
> +		result= octstr_imm("Unauthorized");				/* 401 */
> +		break;
> +	case HTTP_FORBIDDEN:
> +		result= octstr_imm("Forbidden");				/* 403 */
> +		break;
> +	case HTTP_NOT_FOUND:
> +		result= octstr_imm("Not Found");				/* 404 */
> +		break;
> +	case HTTP_BAD_METHOD:
> +		result= octstr_imm("Method Not Allowed");		/* 405 */
> +		break;
> +	case HTTP_NOT_ACCEPTABLE:
> +		result= octstr_imm("Not Acceptable");			/* 406 */
> +		break;
> +	case HTTP_REQUEST_ENTITY_TOO_LARGE:
> +		result= octstr_imm("Request Entity Too Large");	/* 413 */
> +		break;
> +	case HTTP_UNSUPPORTED_MEDIA_TYPE:
> +		result= octstr_imm("Unsupported Media Type");	/* 415 */
> +		break;
> +	case HTTP_INTERNAL_SERVER_ERROR:
> +		result= octstr_imm("Internal Server Error");	/* 500 */
> +		break;
> +	case HTTP_NOT_IMPLEMENTED:
> +		result= octstr_imm("Not Implemented")	;		/* 501 */
> +		break;
> +	case HTTP_BAD_GATEWAY:
> +		result= octstr_imm("Bad Gateway");				/* 502 */
> +		break;
> +	}
> +	return result;
> +}
> +
>
>  void http_send_reply(HTTPClient *client, int status, List *headers,
>      	    	     Octstr *body)
> @@ -2347,9 +2422,9 @@
>      int ret;
>
>      if (client->use_version_1_0)
> -    	response = octstr_format("HTTP/1.0 %d Foo\r\n", status);
> +    	response = octstr_format("HTTP/1.0 %d %S\r\n", status,
> http_reason_phrase(status));
>      else
> -    	response = octstr_format("HTTP/1.1 %d Foo\r\n", status);
> +    	response = octstr_format("HTTP/1.1 %d %S\r\n", status,
> http_reason_phrase(status));
>
>      /* identify ourselfs */
>      octstr_format_append(response, "Server: " GW_NAME "/%s\r\n",
>  GW_VERSION);
>
>
> --
> Zoltan Dudas
> Software Engineer
> SEI Magyarorszag Kft.
> WEB: http://www.sei-it.com
> E-Mail: [email protected]
> Phone: +36 52 889 532
> Fax: +36 52 889 599

-- 
Best regards / Mit besten Grüßen aus Düsseldorf

Dipl.-Ing.
Alexander Malysh
___________________________________________

Centrium GmbH
Vogelsanger Weg 80
40470 Düsseldorf

Fon: +49 (0211) 74 84 51 80
Fax: +49 (0211) 277 49 109

email: [email protected]
web: www.centrium.de
msn: [email protected]
icq: 98063111
___________________________________________

Please avoid sending me Word, Excel or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.