From 5ead3f6fee5605ecc3280677ae04e4baa3629747 Mon Sep 17 00:00:00 2001 From: Fabrice Fontaine Date: Tue, 21 Sep 2010 17:23:58 +0200 Subject: [PATCH] Add Content-Language iff Accept-Language Add Content-Language header in the response if and only if there is an Accept-Language header in the request. Manually ported from revision d2238615e347c45c6abd255597d304cf50b763b5. --- ChangeLog | 7 +++++++ upnp/src/genlib/net/http/httpreadwrite.c | 12 +++++++++--- upnp/src/genlib/net/http/webserver.c | 16 ++++++++++++++-- upnp/src/inc/webserver.h | 1 + 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2eae386..6b14335 100644 --- a/ChangeLog +++ b/ChangeLog @@ -221,6 +221,13 @@ Version 1.8.0 Version 1.6.7 ******************************************************************************* +2010-09-21 Fabrice Fontaine + + Add Content-Language iff Accept-Language + + Add Content-Language header in the response if and only if there is an + Accept-Language header in the request. + 2010-09-21 Fabrice Fontaine Addition of WEB_SERVER_CONTENT_LANGUAGE parameter diff --git a/upnp/src/genlib/net/http/httpreadwrite.c b/upnp/src/genlib/net/http/httpreadwrite.c index 3b02fc8..901670c 100644 --- a/upnp/src/genlib/net/http/httpreadwrite.c +++ b/upnp/src/genlib/net/http/httpreadwrite.c @@ -1908,7 +1908,8 @@ http_SendStatusResponse( IN SOCKINFO * info, * 'G': arg = range information // add range header * 'h': arg = off_t number // appends off_t number * 'K': (no args) // add chunky header - * 'L': (no args) appends HTTP Content-Language: header if + * 'L': arg = language information // add Content-Language header if + * Accept-Language header is not empty and if * WEB_SERVER_CONTENT_LANGUAGE is not empty * 'N': arg1 = off_t content_length // content-length header * 'q': arg1 = http_method_t // request start line and HOST header @@ -2055,8 +2056,13 @@ http_MakeMessage( INOUT membuffer * buf, } } else if ( c == 'L' ) { // Add CONTENT-LANGUAGE header only if WEB_SERVER_CONTENT_LANGUAGE - // is not empty - if (strcmp( WEB_SERVER_CONTENT_LANGUAGE, "" ) && http_MakeMessage( + // is not empty and if Accept-Language header is not empty + struct SendInstruction *RespInstr; + RespInstr = (struct SendInstruction *) + va_arg( argp, struct SendInstruction *); + assert( RespInstr ); + if (strcmp( RespInstr->AcceptLanguageHeader, "" ) && + strcmp( WEB_SERVER_CONTENT_LANGUAGE, "" ) && http_MakeMessage( buf, http_major_version, http_minor_version, "ssc", "CONTENT-LANGUAGE: ", WEB_SERVER_CONTENT_LANGUAGE ) != 0 ) { diff --git a/upnp/src/genlib/net/http/webserver.c b/upnp/src/genlib/net/http/webserver.c index ec0ef41..1a1ea90 100644 --- a/upnp/src/genlib/net/http/webserver.c +++ b/upnp/src/genlib/net/http/webserver.c @@ -1128,6 +1128,12 @@ CheckOtherHTTPHeaders( IN http_message_t * Req, return RetCode; } break; + case HDR_ACCEPT_LANGUAGE: + { + memcpy( RespInstr->AcceptLanguageHeader, TmpBuf, + sizeof( RespInstr->AcceptLanguageHeader ) - 1 ); + break; + } default: /* TODO @@ -1142,7 +1148,6 @@ CheckOtherHTTPHeaders( IN http_message_t * Req, case HDR_CONTENT_LOCATION://return 1; case HDR_ACCEPT: //return 1; case HDR_ACCEPT_CHARSET://return 1; - case HDR_ACCEPT_LANGUAGE://return 1; case HDR_USER_AGENT: break;//return 1; */ @@ -1404,6 +1409,7 @@ process_request( IN http_message_t * req, HTTP_PARTIAL_CONTENT, // status code UpnpFileInfo_get_ContentType(finfo), // content type RespInstr, // range info + RespInstr, // language info "LAST-MODIFIED: ", UpnpFileInfo_get_LastModified(finfo), X_USER_AGENT, @@ -1420,6 +1426,7 @@ process_request( IN http_message_t * req, RespInstr->ReadSendSize, // content length UpnpFileInfo_get_ContentType(finfo), // content type RespInstr, // range info + RespInstr, // language info "LAST-MODIFIED: ", UpnpFileInfo_get_LastModified(finfo), X_USER_AGENT, @@ -1435,6 +1442,7 @@ process_request( IN http_message_t * req, "RK" "TLD" "s" "tcS" "Xc" "sCc", HTTP_OK, // status code UpnpFileInfo_get_ContentType(finfo), // content type + RespInstr, // language info "LAST-MODIFIED: ", UpnpFileInfo_get_LastModified(finfo), X_USER_AGENT, @@ -1452,6 +1460,7 @@ process_request( IN http_message_t * req, HTTP_OK, // status code RespInstr->ReadSendSize, // content length UpnpFileInfo_get_ContentType(finfo), // content type + RespInstr, // language info "LAST-MODIFIED: ", UpnpFileInfo_get_LastModified(finfo), X_USER_AGENT, @@ -1466,6 +1475,7 @@ process_request( IN http_message_t * req, "R" "TLD" "s" "tcS" "b" "Xc" "sCc", HTTP_OK, // status code UpnpFileInfo_get_ContentType(finfo), // content type + RespInstr, // language info "LAST-MODIFIED: ", UpnpFileInfo_get_LastModified(finfo), X_USER_AGENT, @@ -1699,6 +1709,8 @@ web_server_callback( IN http_parser_t * parser, RespInstr.IsChunkActive = 0; RespInstr.IsRangeActive = 0; RespInstr.IsTrailers = 0; + memset( RespInstr.AcceptLanguageHeader, 0, + sizeof( RespInstr.AcceptLanguageHeader ) ); // init membuffer_init( &headers ); membuffer_init( &filename ); @@ -1753,7 +1765,7 @@ web_server_callback( IN http_parser_t * parser, http_MakeMessage( &headers, 1, 1, - "RLTDSXcCc", + "RTLSXcCc", ret, "text/html", X_USER_AGENT ); diff --git a/upnp/src/inc/webserver.h b/upnp/src/inc/webserver.h index 71e4f94..8ea2638 100644 --- a/upnp/src/inc/webserver.h +++ b/upnp/src/inc/webserver.h @@ -48,6 +48,7 @@ struct SendInstruction int IsRangeActive; int IsTrailers; char RangeHeader[200]; + char AcceptLanguageHeader[200]; off_t RangeOffset; off_t ReadSendSize; // Read from local source and send on the network. long RecvWriteSize; // Recv from the network and write into local file.