Skip to content

Commit

Permalink
UA commonality
Browse files Browse the repository at this point in the history
  • Loading branch information
stronnag committed Jun 10, 2024
1 parent 098dd95 commit 7b2d703
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('mwptools', 'c', 'vala', version : '7.162.458', meson_version : '>= 0.60')
project('mwptools', 'c', 'vala', version : '7.162.723', meson_version : '>= 0.60')

# vala / clang16 workaround

Expand Down
18 changes: 17 additions & 1 deletion src/mwp/mapsources.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,22 @@ public class SoupProxy : Soup.Server {
private Soup.Session session;
private string? basename = null;
private string? extname = null;
private const string UASTR = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:%d1.0) Gecko/%d%d%d Firefox/%d.0.%d";

private string make_ua() {
int yr = new DateTime.now_local ().get_year();
var r = new Rand();
string ua = UASTR.printf(
r.int_range(3,14),
r.int_range(yr-4,yr),
r.int_range(11,12),
r.int_range(10,30),
r.int_range(3,14),
r.int_range(1,10));
return ua;
}

public SoupProxy(bool _offline) {
public SoupProxy(bool _offline) {
offline = _offline;
this.add_handler (null, default_handler);
session = new Soup.Session ();
Expand Down Expand Up @@ -192,13 +206,15 @@ public class SoupProxy : Soup.Server {
var xpath = rewrite_path(path);
var message = new Soup.Message ("GET", xpath);
#if COLDSOUP
message.request_headers.append("User-Agent",make_ua());
session.send_message (message);
if(message.status_code == 200) {
msg.set_response ("image/png", Soup.MemoryUse.COPY,
message.response_body.data);
}
msg.set_status(message.status_code);
#else
message.get_request_headers().append("User-Agent",make_ua());
try {
var b = session.send_and_read (message);
msg.set_response ("image/png", Soup.MemoryUse.COPY, b.get_data());
Expand Down

0 comments on commit 7b2d703

Please sign in to comment.