Skip to content

Instantly share code, notes, and snippets.

@aw
Last active May 28, 2020 23:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aw/7b0159ae4f4eb1e2f65e946876d133b1 to your computer and use it in GitHub Desktop.
Save aw/7b0159ae4f4eb1e2f65e946876d133b1 to your computer and use it in GitHub Desktop.
[PicoLisp] Store extra HTTP headers in global variable
# load this code after loading http.l
# ex: pil http.l headers-patch.l --server 8000 yourcode.l
(patch _htHead
'(T (if (eol) (char) (line T) @S))
(fill '(T (if (eol) (char) (when @ (push '*Headers (list @ (cdr (line))))))
. @S) ) )
# v1
diff --git a/lib/http.l b/lib/http.l
index f274334..4046537 100644
--- a/lib/http.l
+++ b/lib/http.l
@@ -267,7 +267,7 @@
(when (till "=^M^J")
(_htSet @ (ht:Pack (cdr (line)) T))
T ) )
- (T (if (eol) (char) (line T))) ) )
+ (T (if (eol) (char) (when @ (push '*Headers (list @ (cdr (line))))))) ) )
(unless *Gate
(and (member ":" *Host) (con (prior @ *Host))) ) )
@aw
Copy link
Author

aw commented May 28, 2020

This minor code change makes HTTP headers accessible through the global variable *Headers. It does not include the headers already processed by PicoLisp such as host, referer, cookie, etc.

Apply the http.patch file to make changes permanent, or load the included headers-patch.l after loading http.l.

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