Skip to content

Samples not language aware #29739

Description

@wetndusty

in many cases changing "Hello, World!" to "Привет, мир!" lead to encoding hell

i guess it not good for newcomers :(

here http2 sample

==========================

const http2 = require('http2');
const fs = require('fs');

const server = http2.createSecureServer({
  key: fs.readFileSync('localhost-privkey.pem'),
  cert: fs.readFileSync('localhost-cert.pem')
});
server.on('error', (err) => console.error(err));

server.on('stream', (stream, headers) => {
  // stream is a Duplex
  stream.respond({
    'content-type': 'text/html',
    ':status': 200
  });
  stream.end('<h1>Hello World (Привет, мир!)</h1>');
});

server.listen(8443);

==================

and how it look in browser -> Hello World (Привет, мир!)

:(

Activity

  1. XhmikosR commented on Sep 20, 2019

    @XhmikosR
    Contributor

    It depends on your editor and its settings. If the file is saved as UTF-8, you shouldn't have such problems.

    But I agree, this is too much.

  2. wetndusty commented on Sep 20, 2019

    @wetndusty
    Author

    my file saved as UTF-8

  3. XhmikosR commented on Sep 20, 2019

    @XhmikosR
    Contributor

    Wrap your sample code above in code blocks so that it's properly formatted. I cannot try unformatted code.

  4. wetndusty commented on Sep 20, 2019

    @wetndusty
    Author

    To generate the certificate and key for this example, run:

    openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \
      -keyout localhost-privkey.pem -out localhost-cert.pem
    
  5. XhmikosR commented on Sep 20, 2019

    @XhmikosR
    Contributor

    What happens if you use 'content-type': 'text/html; charset=utf-8'?

  6. wetndusty commented on Sep 20, 2019

    @wetndusty
    Author

    What happens if you use 'content-type': 'text/html; charset=utf-8'?

    not work

  7. XhmikosR commented on Sep 20, 2019

    @XhmikosR
    Contributor

    Maybe there's something else wrong, then.

    Let's wait for others to chime in.

  8. wetndusty commented on Sep 20, 2019

    @wetndusty
    Author

    i recheck 'content-type': 'text/html; charset=utf-8' work as expected :) typo :) was utf8

    so i guess sample at page https://nodejs.org/dist/latest-v12.x/docs/api/http2.html under title "Server-side example" should be changed at line with code
    'content-type': 'text/html',
    with
    'content-type': 'text/html; charset=utf-8',

    and sample become international friendly :)

  9. wetndusty commented on Sep 20, 2019

    @wetndusty
    Author

    google search 'content-type': 'text/html' site:nodejs.org should return zero :)

  10. wetndusty commented on Sep 20, 2019

    @wetndusty
    Author

    i tried search utf8 at site nodejs.org - it return many - maybe it not ok?

  11. XhmikosR commented on Sep 20, 2019

    @XhmikosR
    Contributor

    The thing is that the translators shouldn't have translated this in the first place, and secondly this should have been caught up in review.

    But anyway mistakes happen so we are here to fix them, including yourself :)

    I'm not sure what's the best solution. The easiest one would be to fix this specific snippet, but for the long term we probably need to standardize this.

    /CC @Trott

  12. Trott commented on Sep 22, 2019

    @Trott
    Member

    @nodejs/i18n Opinions on how best to address this?

  13. XhmikosR commented on Sep 25, 2019

    @XhmikosR
    Contributor

    @wetndusty where's this snippet exactly on the website?

  14. wetndusty commented on Sep 26, 2019

    @wetndusty
    Author
  15. XhmikosR commented on Sep 26, 2019

    @XhmikosR
    Contributor

    That's in the core @Trott

  16. 6 remaining items

  17. added
    httpIssues and PRs related to the http subsystem.
    on Sep 27, 2019
  18. added
    http2Issues and PRs related to the http2 subsystem.
    and removed
    httpIssues and PRs related to the http subsystem.
    on Sep 28, 2019
  19. lpinca commented on Sep 29, 2019

    @lpinca
    Member

    This is valid for many examples and not just this one https://nodejs.org/dist/latest-v12.x/docs/api/http2.html#http2_server_side_example. In my opinion we should either use Content-Type: text/html; charset=utf-8 for all of them or none.

    To be pedantic the examples work as intended and the problem only happens when changing the original data so this is expected. I mean if you are changing the example you should understand your change and what are the consequences that this entails (also update the value of the Content-Type header in this particular case).

  20. wetndusty commented on Sep 29, 2019

    @wetndusty
    Author

    it sometime hard for newcomers - change hello world to local language is common practice - so change base code to be newcomers friendly variant is not so bad idea (IMHO)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.http2Issues and PRs related to the http2 subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions