Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http status string depends on system locale only #426

Closed
vitlav opened this issue Jul 8, 2022 · 6 comments
Closed

http status string depends on system locale only #426

vitlav opened this issue Jul 8, 2022 · 6 comments
Assignees
Labels
bug Something isn't working priority-low
Milestone

Comments

@vitlav
Copy link

vitlav commented Jul 8, 2022

In answer to GET / request with Accept-Language: en
I still get localized http status 200 string

Server:
# LANG=zh_CN /usr/sbin/cupsd -l

Client:
$ curl -H "User-Agent: Mozilla/Firefox" -H "Accept-Language: en" -H "Content-Type: text/plain; charset=utf-8" -v http://localhost:631 >/dev/null
*   Trying 127.0.0.1:631...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to localhost (127.0.0.1) port 631 (#0)
> GET / HTTP/1.1
> Host: localhost:631
> Accept: */*
> User-Agent: Mozilla/Firefox
> Accept-Language: en
> Content-Type: text/plain; charset=utf-8
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 确定
< Connection: Keep-Alive
< Content-Language: en
< Content-Length: 2301

I guess http answer have to use language as in Content-Language field.

@vitlav
Copy link
Author

vitlav commented Jul 9, 2022

By some reason httpStatus string localize to the current locale, not request locale (Content-Language).

/*
 * 'httpStatus()' - Return a short string describing a HTTP status code.
 *
 * The returned string is localized to the current POSIX locale and is based
 * on the status strings defined in RFC 7231.
 */

const char *                            /* O - Localized status string */
httpStatus(http_status_t status)        /* I - HTTP status code */
{
  _cups_globals_t *cg = _cupsGlobals(); /* Global data */


  if (!cg->lang_default)
    cg->lang_default = cupsLangDefault();

  return (_httpStatus(cg->lang_default, status));
}

@vitlav
Copy link
Author

vitlav commented Jul 9, 2022

Latest commit changed it has a wrong description (as it localized status strings based on Accept-Languages)
41e6c1f

@vitlav
Copy link
Author

vitlav commented Jul 9, 2022

the issue can be resolved via replace httpStatus() with _httpStatus().

@michaelrsweet
Copy link
Member

Do not use private APIs

_httpStatus is private, httpStatus uses the current locale. There is no API to return a localized HTTP status code description for an arbitrary language/locale.

If you are writing an HTTP server, use the httpWriteResponse API to get a localized status code description in the HTTP response.

@michaelrsweet michaelrsweet added bug Something isn't working priority-low labels Jul 10, 2022
@michaelrsweet michaelrsweet added this to the v2.4.x milestone Jul 10, 2022
@michaelrsweet
Copy link
Member

And to close the loop on this now that I've had a chance to look at the code, httpWriteResponse is using httpStatus instead of the private API with the correct Content-Language localized string. Not that this makes it a serious issue because the text in the response isn't really intended for human consumption...

I'll put together a fix that gets the locale for the response language and uses the localized string for it instead of the default (system) locale.

@michaelrsweet
Copy link
Member

[master 02c6a72] Localize the HTTP response using the Content-Language value (Issue #426)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-low
Projects
None yet
Development

No branches or pull requests

2 participants