diff -ru links-0.96/default.c links-0.96+true-referer/default.c
--- links-0.96/default.c	Sat Oct  6 17:16:08 2001
+++ links-0.96+true-referer/default.c	Sat Oct  6 17:13:57 2001
@@ -855,7 +855,7 @@
 unsigned char ftp_proxy[MAX_STR_LEN] = "";
 
 unsigned char fake_referer[MAX_STR_LEN] = "";
-int referer;   /* values: REFERER_NONE (default), REFERER_SAME_URL, REFERER_FAKE */
+int referer;   /* values: REFERER_NONE (default), REFERER_TRUE, REFERER_SAME_URL, REFERER_FAKE */
 
 unsigned char download_dir[MAX_STR_LEN] = "";
 
@@ -899,7 +899,7 @@
 	1, gen_cmd, num_rd, num_wr, 0, 1, &http_bugs.allow_blacklist, "http_bugs.allow_blacklist", "http-bugs.allow-blacklist",
 	1, gen_cmd, num_rd, num_wr, 0, 1, &http_bugs.bug_302_redirect, "http_bugs.bug_302_redirect", "http-bugs.bug-302-redirect",
 	1, gen_cmd, num_rd, num_wr, 0, 1, &http_bugs.bug_post_no_keepalive, "http_bugs.bug_post_no_keepalive", "http-bugs.bug_post-no-keepalive",
-	1, gen_cmd, num_rd, num_wr, 0, 2, &referer, "http_referer", "http-referer",
+	1, gen_cmd, num_rd, num_wr, 0, 3, &referer, "http_referer", "http-referer",
 	1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN, fake_referer, "fake_referer", "fake-referer",
 	1, gen_cmd, str_rd, str_wr, 0, MAX_STR_LEN, default_anon_pass, "ftp.anonymous_password", "ftp.anonymous-password",
 	1, gen_cmd, cp_rd, NULL, 0, 0, &dds.assume_cp, "assume_codepage", "assume-codepage",
diff -ru links-0.96/http.c links-0.96+true-referer/http.c
--- links-0.96/http.c	Sat Oct  6 17:16:08 2001
+++ links-0.96+true-referer/http.c	Sat Oct  6 17:13:57 2001
@@ -249,9 +249,32 @@
 		add_to_str(&hdr, &l, fake_referer);
 		add_to_str(&hdr, &l, "\r\n");
 		break;
+
+		case REFERER_TRUE:
+		if (c->prev_url && c->prev_url[0])
+		{
+		  unsigned char *etk;
+		  add_to_str(&hdr, &l, "Referer: ");
+		  if (etk = strchr(c->prev_url, '\1')) /* braindead ;-) */
+		    add_bytes_to_str(&hdr, &l, c->prev_url, etk - c->prev_url);
+		  else
+		    add_to_str(&hdr, &l, c->prev_url);
+		  add_to_str(&hdr, &l, "\r\n");
+	        }
+		break;
 		
 		case REFERER_SAME_URL:
-		add_to_str(&hdr, &l, "Referer: ");
+		add_to_str(&hdr, &l, "Referer: http://");
+		if ((h = get_host_name(host))) {
+			add_to_str(&hdr, &l, h);
+			mem_free(h);
+			if ((h = get_port_str(host))) {
+				add_to_str(&hdr, &l, ":");
+				add_to_str(&hdr, &l, h);
+				mem_free(h);
+			}
+		}
+		if (upcase(c->url[0]) != 'P') add_to_str(&hdr, &l, "/");
 		if (!post) add_to_str(&hdr, &l, u);
 		else add_bytes_to_str(&hdr, &l, u, post - u - 1);
 		add_to_str(&hdr, &l, "\r\n");
diff -ru links-0.96/intl/czech.lng links-0.96+true-referer/intl/czech.lng
--- links-0.96/intl/czech.lng	Mon Jul  2 02:28:05 2001
+++ links-0.96+true-referer/intl/czech.lng	Sat Oct  6 17:13:57 2001
@@ -138,6 +138,11 @@
 T_CANT_GET_SOCKET_STATE, "Nemůžu zjistit stav socketu",
 T_BAD_HTTP_RESPONSE, "Špatná HTTP odpověď (asi bugovitý server)",
 T_HTTP_100, "HTTP 100 (?)",
+T_FAKE_REFERER, "Falešný HTTP referer",
+T_REFERER_NONE, "Neposílat HTTP referer",
+T_REFERER_TRUE, "Posílat předchozí URL jako referer (normalní a NEBEZPEČNÉ)",
+T_REFERER_SAME_URL, "Posílat vyžádané URL jako referer",
+T_REFERER_FAKE, "Posílat falešný HTTP referer",
 T_NO_CONTENT, "Žádnej obsah",
 T_UNKNOWN_FILE_TYPE, "Neznámej typ souboru",
 T_ERROR_OPENING_FILE, "Chybička při čtení souboru",
diff -ru links-0.96/intl/english.lng links-0.96+true-referer/intl/english.lng
--- links-0.96/intl/english.lng	Sat Oct  6 17:16:08 2001
+++ links-0.96+true-referer/intl/english.lng	Sat Oct  6 17:13:57 2001
@@ -140,6 +140,7 @@
 T_HTTP_100, "HTTP 100 (???)",
 T_FAKE_REFERER, "Fixed HTTP Referer",
 T_REFERER_NONE, "No referer",
+T_REFERER_TRUE, "Send previous URL as referer (normal operation, INSECURE)",
 T_REFERER_SAME_URL, "Send requested URL as referer",
 T_REFERER_FAKE, "Fixed referer",
 T_NO_CONTENT, "No content",
diff -ru links-0.96/links.h links-0.96+true-referer/links.h
--- links-0.96/links.h	Sat Oct  6 17:16:08 2001
+++ links-0.96+true-referer/links.h	Sat Oct  6 17:13:57 2001
@@ -632,6 +632,7 @@
 	struct connection *prev;
 	tcount count;
 	unsigned char *url;
+	unsigned char *prev_url;
 	int running;
 	int state;
 	int prev_error;
@@ -754,7 +755,7 @@
 void retry_connection(struct connection *c);
 void abort_connection(struct connection *c);
 void end_connection(struct connection *c);
-int load_url(unsigned char *, struct status *, int, int);
+int load_url(unsigned char *, unsigned char *, struct status *, int, int);
 void change_connection(struct status *, struct status *, int);
 void detach_connection(struct status *, int);
 void abort_all_connections();
@@ -1466,6 +1467,7 @@
 	unsigned char *tq_prog;
 	int tq_prog_flags;
 	unsigned char *dn_url;
+	unsigned char *ref_url;
 	unsigned char *search_word;
 	unsigned char *last_search_word;
 	int search_direction;
@@ -1991,6 +1993,7 @@
 #define REFERER_NONE 0
 #define REFERER_SAME_URL 1
 #define REFERER_FAKE 2
+#define REFERER_TRUE 3
 
 extern unsigned char http_proxy[];
 extern unsigned char ftp_proxy[];
diff -ru links-0.96/main.c links-0.96+true-referer/main.c
--- links-0.96/main.c	Sun Apr  8 22:46:06 2001
+++ links-0.96+true-referer/main.c	Sat Oct  6 17:13:57 2001
@@ -163,7 +163,7 @@
 		if (stat->state >= 0) change_connection(stat, NULL, PRI_CANCEL);
 		u = stracpy(ce->redirect);
 		if (!http_bugs.bug_302_redirect) if (!ce->redirect_get && (p = strchr(ce->url, POST_CHAR))) add_to_strn(&u, p);
-		load_url(u, stat, PRI_MAIN, 0);
+		load_url(u, ce->url, stat, PRI_MAIN, 0);
 		mem_free(u);
 		return;
 	}
@@ -280,7 +280,7 @@
 		dump_stat.end = end_dump;
 		dump_pos = 0;
 		if (!(uu = translate_url(u, wd = get_cwd()))) uu = stracpy(u);
-		if (load_url(uu, &dump_stat, PRI_MAIN, 0)) goto ttt;
+		if (load_url(uu, NULL, &dump_stat, PRI_MAIN, 0)) goto ttt;
 		mem_free(uu);
 		if (wd) mem_free(wd);
 	}
diff -ru links-0.96/menu.c links-0.96+true-referer/menu.c
--- links-0.96/menu.c	Sat Oct  6 17:16:08 2001
+++ links-0.96+true-referer/menu.c	Sat Oct  6 17:13:57 2001
@@ -438,7 +438,7 @@
  	do_dialog(term, d, getml(d, NULL));
 }
 
-unsigned char *http_labels[] = { TEXT(T_USE_HTTP_10), TEXT(T_ALLOW_SERVER_BLACKLIST), TEXT(T_BROKEN_302_REDIRECT), TEXT(T_NO_KEEPALIVE_AFTER_POST_REQUEST), TEXT(T_REFERER_NONE), TEXT(T_REFERER_SAME_URL), TEXT(T_REFERER_FAKE), TEXT(T_FAKE_REFERER) };
+unsigned char *http_labels[] = { TEXT(T_USE_HTTP_10), TEXT(T_ALLOW_SERVER_BLACKLIST), TEXT(T_BROKEN_302_REDIRECT), TEXT(T_NO_KEEPALIVE_AFTER_POST_REQUEST), TEXT(T_REFERER_NONE), TEXT(T_REFERER_TRUE), TEXT(T_REFERER_SAME_URL), TEXT(T_REFERER_FAKE), TEXT(T_FAKE_REFERER) };
 
 void httpopt_fn(struct dialog_data *dlg)
 {
@@ -448,8 +448,8 @@
 	int y = 0;
 	checkboxes_width(term, dlg->dlg->udata, &max, max_text_width);
 	checkboxes_width(term, dlg->dlg->udata, &min, min_text_width);
-	max_text_width(term, http_labels[7], &max);
-	min_text_width(term, http_labels[7], &min);
+	max_text_width(term, http_labels[8], &max);
+	min_text_width(term, http_labels[8], &min);
 	max_buttons_width(term, dlg->items + dlg->n - 2, 2, &max);
 	min_buttons_width(term, dlg->items + dlg->n - 2, 2, &min);
 	w = term->x * 9 / 10 - 2 * DIALOG_LB;
@@ -460,7 +460,7 @@
 	rw = 0;
 	dlg_format_checkboxes(NULL, term, dlg->items, dlg->n - 3, 0, &y, w, &rw, dlg->dlg->udata);
 	y++;
-	dlg_format_text(NULL, term, http_labels[7], 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
+	dlg_format_text(NULL, term, http_labels[8], 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
 	y+=2;
 	dlg_format_buttons(NULL, term, dlg->items + dlg->n - 2, 2, 0, &y, w, &rw, AL_CENTER);
 	w = rw;
@@ -471,8 +471,8 @@
 	y = dlg->y + DIALOG_TB + 1;
 	dlg_format_checkboxes(term, term, dlg->items, dlg->n - 3, dlg->x + DIALOG_LB, &y, w, NULL, dlg->dlg->udata);
 	y++;
-	dlg_format_text(term, term, http_labels[7], dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
-	dlg_format_field(term, term, dlg->items + 7, dlg->x + DIALOG_LB, &y, w, NULL, AL_LEFT);
+	dlg_format_text(term, term, http_labels[8], dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
+	dlg_format_field(term, term, dlg->items + 8, dlg->x + DIALOG_LB, &y, w, NULL, AL_LEFT);
 	y++;
 	dlg_format_buttons(term, term, dlg->items + dlg->n - 2, 2, dlg->x + DIALOG_LB, &y, w, &rw, AL_CENTER);
 }
@@ -482,8 +482,8 @@
 {
 	struct http_bugs *bugs = (struct http_bugs *)di->cdata;
 	struct dialog *d;
-	if (!(d = mem_alloc(sizeof(struct dialog) + 11 * sizeof(struct dialog_item)))) return 0;
-	memset(d, 0, sizeof(struct dialog) + 11 * sizeof(struct dialog_item));
+	if (!(d = mem_alloc(sizeof(struct dialog) + 12 * sizeof(struct dialog_item)))) return 0;
+	memset(d, 0, sizeof(struct dialog) + 12 * sizeof(struct dialog_item));
 	d->title = TEXT(T_HTTP_BUG_WORKAROUNDS);
 	d->fn = httpopt_fn;
 	d->udata = http_labels;
@@ -510,26 +510,31 @@
 	d->items[4].data = (void *)&referer;
 	d->items[5].type = D_CHECKBOX;
 	d->items[5].gid = 1;
-	d->items[5].gnum = REFERER_SAME_URL;
+	d->items[5].gnum = REFERER_TRUE;
 	d->items[5].dlen = sizeof(int);
 	d->items[5].data = (void *)&referer;
 	d->items[6].type = D_CHECKBOX;
 	d->items[6].gid = 1;
-	d->items[6].gnum = REFERER_FAKE;
+	d->items[6].gnum = REFERER_SAME_URL;
 	d->items[6].dlen = sizeof(int);
 	d->items[6].data = (void *)&referer;
-	d->items[7].type = D_FIELD;
-	d->items[7].dlen = MAX_STR_LEN;
-	d->items[7].data = fake_referer;
-	d->items[8].type = D_BUTTON;
-	d->items[8].gid = B_ENTER;
-	d->items[8].fn = ok_dialog;
-	d->items[8].text = TEXT(T_OK);
+	d->items[7].type = D_CHECKBOX;
+	d->items[7].gid = 1;
+	d->items[7].gnum = REFERER_FAKE;
+	d->items[7].dlen = sizeof(int);
+	d->items[7].data = (void *)&referer;
+	d->items[8].type = D_FIELD;
+	d->items[8].dlen = MAX_STR_LEN;
+	d->items[8].data = fake_referer;
 	d->items[9].type = D_BUTTON;
-	d->items[9].gid = B_ESC;
-	d->items[9].fn = cancel_dialog;
-	d->items[9].text = TEXT(T_CANCEL);
-	d->items[10].type = D_END;
+	d->items[9].gid = B_ENTER;
+	d->items[9].fn = ok_dialog;
+	d->items[9].text = TEXT(T_OK);
+	d->items[10].type = D_BUTTON;
+	d->items[10].gid = B_ESC;
+	d->items[10].fn = cancel_dialog;
+	d->items[10].text = TEXT(T_CANCEL);
+	d->items[11].type = D_END;
  	do_dialog(dlg->win->term, d, getml(d, NULL));
 	return 0;
 }
diff -ru links-0.96/sched.c links-0.96+true-referer/sched.c
--- links-0.96/sched.c	Mon Jun 11 12:04:54 2001
+++ links-0.96+true-referer/sched.c	Sat Oct  6 17:13:57 2001
@@ -527,7 +527,7 @@
 	return u;
 }
 
-int load_url(unsigned char *url, struct status *stat, int pri, int no_cache)
+int load_url(unsigned char *url, unsigned char *prev_url, struct status *stat, int pri, int no_cache)
 {
 	struct cache_entry *e = NULL;
 	struct connection *c;
@@ -587,6 +587,7 @@
 	memset(c, 0, sizeof(struct connection));
 	c->count = connection_count++;
 	c->url = u;
+	c->prev_url = prev_url;
 	c->running = 0;
 	c->prev_error = 0;
 	c->from = no_cache >= NC_RELOAD || !e || e->frag.next == &e->frag || ((struct fragment *)e->frag.next)->offset ? 0 : ((struct fragment *)e->frag.next)->length;
diff -ru links-0.96/session.c links-0.96+true-referer/session.c
--- links-0.96/session.c	Sat Jun  2 00:39:00 2001
+++ links-0.96+true-referer/session.c	Sat Oct  6 17:15:00 2001
@@ -518,7 +518,7 @@
 			down->win->handler(down->win, &ev, 0);
 		}
 		/*if (!strchr(down->url, POST_CHAR)) {*/
-			load_url(down->url, &down->stat, PRI_DOWNLOAD, NC_CACHE);
+			load_url(down->url, ce->url, &down->stat, PRI_DOWNLOAD, NC_CACHE);
 			return;
 		/*} else {
 			unsigned char *msg = init_str();
@@ -676,7 +676,7 @@
 	down->ses = ses;
 	down->remotetime = 0;
 	add_to_list(downloads, down);
-	load_url(url, &down->stat, PRI_DOWNLOAD, NC_CACHE);
+	load_url(url, ses->ref_url, &down->stat, PRI_DOWNLOAD, NC_CACHE);
 	display_download(ses->term, down, ses);
 }
 
@@ -849,7 +849,7 @@
 	w->ses->loading_url = stracpy(w->url);
 	w->ses->wtd = w->wtd;
 	w->ses->wtd_target = w->target;
-	load_url(w->ses->loading_url, &w->ses->loading, w->pri, w->cache);
+	load_url(w->ses->loading_url, w->ses->ref_url, &w->ses->loading, w->pri, w->cache);
 }
 
 void post_no(struct wtd_data *w)
@@ -876,7 +876,7 @@
 		ses->loading_url = url;
 		ses->wtd = wtd;
 		ses->wtd_target = target;
-		load_url(url, &ses->loading, pri, cache);
+		load_url(url, ses->ref_url, &ses->loading, pri, cache);
 		return;
 	}
 	w->ses = ses;
@@ -897,6 +897,7 @@
 int do_move(struct session *ses, struct status **stat)
 {
 	struct cache_entry *ce = NULL;
+	int l = 0;
 	if (!ses->loading_url) {
 		internal("no ses->loading_url");
 		return 0;
@@ -917,6 +918,9 @@
 		abort_loading(ses);
 		if (!list_empty(ses->history)) *stat = &cur_loc(ses)->stat;
 		else *stat = NULL;
+		if (ses->ref_url) mem_free(ses->ref_url);
+		ses->ref_url = init_str();
+		add_to_str(&ses->ref_url, &l, ce->url);
 		if (w == WTD_FORWARD || w == WTD_IMGMAP) {
 			ses_goto(ses, u, ses->wtd_target, PRI_MAIN, NC_CACHE, w, gp, end_load, 1);
 			return 2;
@@ -1144,6 +1148,7 @@
 {
 	static int stop_recursion = 0;
 	struct file_to_load *ftl;
+	struct f_data_c *fd = current_frame(ses);
 	int more;
 	if (stop_recursion) return;
 	stop_recursion = 1;
@@ -1151,7 +1156,7 @@
 		more = 0;
 		foreach(ftl, ses->more_files) if (!ftl->req_sent) {
 			ftl->req_sent = 1;
-			load_url(ftl->url, &ftl->stat, ftl->pri, NC_CACHE);
+			load_url(ftl->url, fd?fd->f_data?fd->f_data->url:NULL:NULL, &ftl->stat, ftl->pri, NC_CACHE);
 			more = 1;
 		}
 	} while (more);
@@ -1342,6 +1347,7 @@
 	if (ses->tq_goto_position) mem_free(ses->tq_goto_position);
 	if (ses->tq_prog) mem_free(ses->tq_prog);
 	if (ses->dn_url) mem_free(ses->dn_url);
+	if (ses->ref_url) mem_free(ses->ref_url),ses->ref_url=NULL;
 	if (ses->search_word) mem_free(ses->search_word);
 	if (ses->last_search_word) mem_free(ses->last_search_word);
 	del_from_list(ses);
@@ -1361,6 +1367,7 @@
 void reload(struct session *ses, int no_cache)
 {
 	struct location *l;
+	struct f_data_c *fd = current_frame(ses);
 	abort_loading(ses);
 	if (no_cache == -1) no_cache = ++ses->reloadlevel;
 	else ses->reloadlevel = no_cache;
@@ -1368,12 +1375,12 @@
 		struct file_to_load *ftl;
 		l->stat.data = ses;
 		l->stat.end = (void *)doc_end_load;
-		load_url(l->vs.url, &l->stat, PRI_MAIN, no_cache);
+		load_url(l->vs.url, ses->ref_url, &l->stat, PRI_MAIN, no_cache);
 		foreach(ftl, ses->more_files) {
 			if (ftl->req_sent && ftl->stat.state >= 0) continue;
 			ftl->stat.data = ftl;
 			ftl->stat.end = (void *)file_end_load;
-			load_url(ftl->url, &ftl->stat, PRI_FRAME, no_cache);
+			load_url(ftl->url, fd?fd->f_data?fd->f_data->url:NULL:NULL, &ftl->stat, PRI_FRAME, no_cache);
 		}
 	}
 }
@@ -1396,6 +1403,9 @@
 void go_back(struct session *ses)
 {
 	unsigned char *url;
+	struct f_data_c *fd = current_frame(ses);
+	int l = 0;
+	
 	ses->reloadlevel = NC_CACHE;
 	if (ses->wtd) {
 		if (1 || ses->wtd != WTD_BACK) {
@@ -1410,6 +1420,11 @@
 	abort_loading(ses);
 	if (!(url = stracpy(((struct location *)ses->history.next)->next->vs.url)))
 		return;
+	if (ses->ref_url) mem_free(ses->ref_url),ses->ref_url=NULL;
+	if (fd && fd->f_data && fd->f_data->url) {
+		ses->ref_url = init_str();
+		add_to_str(&ses->ref_url, &l, fd->f_data->url);
+	}
 	ses_goto(ses, url, NULL, PRI_MAIN, NC_ALWAYS_CACHE, WTD_BACK, NULL, end_load, 0);
 }
 
@@ -1418,6 +1433,9 @@
 	unsigned char *u;
 	unsigned char *pos;
 	void (*fn)(struct session *, unsigned char *);
+        struct f_data_c *fd = current_frame(ses);
+        int l = 0;
+
 	if ((fn = get_external_protocol_function(url))) {
 		fn(ses, url);
 		return;
@@ -1439,6 +1457,11 @@
 		}
 	}
 	abort_loading(ses);
+	if (ses->ref_url) mem_free(ses->ref_url), ses->ref_url=NULL;
+	if (fd && fd->f_data && fd->f_data->url) {
+ 		ses->ref_url = init_str();
+		add_to_str(&ses->ref_url, &l, fd->f_data->url);
+	}
 	ses_goto(ses, u, target, PRI_MAIN, NC_CACHE, wtd, pos, end_load, 0);
 	/*abort_loading(ses);*/
 }
diff -ru links-0.96/view.c links-0.96+true-referer/view.c
--- links-0.96/view.c	Sat Jun 16 13:34:07 2001
+++ links-0.96+true-referer/view.c	Sat Oct  6 17:13:57 2001
@@ -2086,6 +2086,8 @@
 void frm_download(struct session *ses, struct f_data_c *fd)
 {
 	struct link *link;
+	int l = 0;
+	
 	if (fd->vs->current_link == -1) return;
 	if (ses->dn_url) mem_free(ses->dn_url), ses->dn_url = NULL;
 	link = &fd->f_data->links[fd->vs->current_link];
@@ -2096,6 +2098,9 @@
 			ses->dn_url = NULL;
 			return;
 		}
+		if (ses->ref_url) mem_free(ses->ref_url);
+		ses->ref_url = init_str();
+		add_to_str(&ses->ref_url, &l, fd->f_data->url);
 		query_file(ses, ses->dn_url, start_download, NULL);
 	}
 }
@@ -2103,21 +2108,33 @@
 void send_download_image(struct terminal *term, void *xxx, struct session *ses)
 {
 	struct f_data_c *fd = current_frame(ses);
+	int l = 0;
+	
 	if (!fd) return;
 	if (fd->vs->current_link == -1) return;
 	if (ses->dn_url) mem_free(ses->dn_url);
-	if ((ses->dn_url = stracpy(fd->f_data->links[fd->vs->current_link].where_img)))
+	if ((ses->dn_url = stracpy(fd->f_data->links[fd->vs->current_link].where_img))) {
+		if (ses->ref_url) mem_free(ses->ref_url);
+		ses->ref_url = init_str();
+		add_to_str(&ses->ref_url, &l, fd->f_data->url);
 		query_file(ses, ses->dn_url, start_download, NULL);
+	}
 }
 
 void send_download(struct terminal *term, void *xxx, struct session *ses)
 {
 	struct f_data_c *fd = current_frame(ses);
+	int l = 0;
+	
 	if (!fd) return;
 	if (fd->vs->current_link == -1) return;
 	if (ses->dn_url) mem_free(ses->dn_url);
-	if ((ses->dn_url = get_link_url(ses, fd, &fd->f_data->links[fd->vs->current_link])))
+	if ((ses->dn_url = get_link_url(ses, fd, &fd->f_data->links[fd->vs->current_link]))) {
+		if (ses->ref_url) mem_free(ses->ref_url);
+		ses->ref_url = init_str();
+		add_to_str(&ses->ref_url, &l, fd->f_data->url);
 		query_file(ses, ses->dn_url, start_download, NULL);
+	}
 }
 
 /* open a link in a new xterm */
@@ -2180,14 +2197,20 @@
 
 void save_url(struct session *ses, unsigned char *url)
 {
+	struct f_data_c *fd = current_frame(ses);
 	unsigned char *u;
+	int l = 0;
+	
 	if (!(u = translate_url(url, ses->term->cwd))) {
 		struct status stat = { NULL, NULL, NULL, NULL, S_BAD_URL, PRI_CANCEL, 0, NULL, NULL };
 		print_error_dialog(ses, &stat, TEXT(T_ERROR));
 		return;
 	}
 	if (ses->dn_url) mem_free(ses->dn_url);
+	if (ses->ref_url) mem_free(ses->ref_url);
 	ses->dn_url = u;
+	ses->ref_url = init_str();
+	add_to_str(&ses->ref_url, &l, fd->f_data->url);
 	query_file(ses, ses->dn_url, start_download, NULL);
 }
 
@@ -2203,12 +2226,19 @@
 
 void save_as(struct terminal *term, void *xxx, struct session *ses)
 {
+	struct f_data_c *fd = current_frame(ses);
 	struct location *l;
+	int len = 0;
+	
 	if (list_empty(ses->history)) return;
 	l = cur_loc(ses);
 	if (ses->dn_url) mem_free(ses->dn_url);
-	if ((ses->dn_url = stracpy(l->vs.url)))
+	if ((ses->dn_url = stracpy(l->vs.url))) {
+		if (ses->ref_url) mem_free(ses->ref_url);
+		ses->ref_url = init_str();
+		add_to_str(&ses->ref_url, &len, fd->f_data->url);
 		query_file(ses, ses->dn_url, start_download, NULL);
+	}
 }
 
 void save_formatted(struct session *ses, unsigned char *file)
