gen_http_headers_insert.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. #
  3. # Generate header insert for HTTP headers
  4. #
  5. # Copyright (c) 2015-2019 Karlson2k (Evgeny Grin) <k2k@yandex.ru>
  6. #
  7. # Copying and distribution of this file, with or without modification, are
  8. # permitted in any medium without royalty provided the copyright notice
  9. # and this notice are preserved. This file is offered as-is, without any
  10. # warranty.
  11. wget -nv http://www.iana.org/assignments/message-headers/perm-headers.csv -O perm-headers.csv || exit
  12. echo Generating...
  13. echo '/**
  14. * @defgroup headers HTTP headers
  15. * These are the standard headers found in HTTP requests and responses.
  16. * See: http://www.iana.org/assignments/message-headers/message-headers.xml
  17. * Registry export date: '$(date -u +%Y-%m-%d)'
  18. * @{
  19. */
  20. /* Main HTTP headers. */' > header_insert_headers.h && \
  21. gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
  22. {
  23. if ($3 == "http") {
  24. gsub(/^\[|^"\[|\]"$|\]$/, "", $5)
  25. rfc_num = substr($5, 4, 4)
  26. if (rfc_num >= 7230 && rfc_num <= 7235)
  27. {
  28. gsub(/\]\[/, "; ", $5)
  29. if (length($4) == 0)
  30. { $4 = "No category" }
  31. else
  32. { sub(/^./, toupper(substr($4, 1, 1)), $4) }
  33. print "/* " sprintf("%-14.14s", $4 ".") " " $5 " */"
  34. print "#define MHD_HTTP_HEADER_" toupper(gensub(/-/, "_", "g", $1)) " \""$1"\""
  35. }
  36. }
  37. }' perm-headers.csv >> header_insert_headers.h && \
  38. echo '
  39. /* Additional HTTP headers. */' >> header_insert_headers.h && \
  40. gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
  41. {
  42. if ($3 == "http") {
  43. gsub(/^\[|^"\[|\]"$|\]$/, "", $5)
  44. rfc_num = substr($5, 4, 4)
  45. if (!(rfc_num >= 7230 && rfc_num <= 7235))
  46. {
  47. gsub(/\]\[/, "; ", $5)
  48. if (length($4) == 0)
  49. { $4 = "No category" }
  50. else
  51. { sub(/^./, toupper(substr($4, 1, 1)), $4) }
  52. print "/* " sprintf("%-14.14s", $4 ".") " " $5 " */"
  53. print "#define MHD_HTTP_HEADER_" toupper(gensub(/-/, "_", "g", $1)) " \""$1"\""
  54. }
  55. }
  56. }' perm-headers.csv >> header_insert_headers.h && \
  57. echo OK && \
  58. rm perm-headers.csv || exit