user/dev discussion of public-inbox itself
 help / color / Atom feed
bc349f8a7a1e633617be39ef6e8028af05a2290f blob 2374 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 
# Copyright (C) 2019 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>

# Standalone PSGI app to provide syntax highlighting as-a-service
# via "highlight" Perl module ("libhighlight-perl" in Debian).
#
# This allows exposing highlight as a persistent HTTP service for
# other scripts via HTTP PUT requests.  PATH_INFO will be used
# as a hint for detecting the language for highlight.
#
# The following example using curl(1) will do the right thing
# regarding the file extension:
#
#   curl -HExpect: -T /path/to/file http://example.com/
#
# You can also force a file extension by giving a path
# (in this case, "c") via:
#
#   curl -HExpect: -T /path/to/file http://example.com/x.c

package PublicInbox::WwwHighlight;
use strict;
use warnings;
use bytes (); # only for bytes::length
use HTTP::Status qw(status_message);
use parent qw(PublicInbox::HlMod);
use PublicInbox::Linkify qw();
use PublicInbox::Hval qw(ascii_html);

# TODO: support highlight(1) for distros which don't package the
# SWIG extension.  Also, there may be admins who don't want to
# have ugly SWIG-generated code in a long-lived Perl process.

sub r ($) {
	my ($code) = @_;
	my $msg = status_message($code);
	my $len = length($msg);
	[ $code, [qw(Content-Type text/plain Content-Length), $len], [$msg] ]
}

# another slurp API hogging up all my memory :<
# This is capped by whatever the PSGI server allows,
# $ENV{GIT_HTTP_MAX_REQUEST_BUFFER} for PublicInbox::HTTP (10 MB)
sub read_in_full ($) {
	my ($env) = @_;

	my $in = $env->{'psgi.input'};
	my $off = 0;
	my $buf = '';
	my $len = $env->{CONTENT_LENGTH} || 8192;
	while (1) {
		my $r = $in->read($buf, $len, $off);
		last unless defined $r;
		return \$buf if $r == 0;
		$off += $r;
	}
	$env->{'psgi.errors'}->print("input read error: $!\n");
	undef;
}

# entry point for PSGI
sub call {
	my ($self, $env) = @_;
	my $req_method = $env->{REQUEST_METHOD};

	return r(405) if $req_method ne 'PUT';

	my $bref = read_in_full($env) or return r(500);
	my $l = PublicInbox::Linkify->new;
	$l->linkify_1($$bref);
	if (my $res = $self->do_hl($bref, $env->{PATH_INFO})) {
		$bref = $res;
	} else {
		$$bref = ascii_html($$bref);
	}
	$l->linkify_2($$bref);

	my $h = [ 'Content-Type', 'text/html; charset=UTF-8' ];
	push @$h, 'Content-Length', bytes::length($$bref);

	[ 200, $h, [ $$bref ] ]
}

1;
debug log:

solving bc349f8 ...
found bc349f8 in https://80x24.org/public-inbox.git

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox