Index: /pjproject/branches/pjproject-0.5-stable/pjlib/src/pj/config.c
===================================================================
--- /pjproject/branches/pjproject-0.5-stable/pjlib/src/pj/config.c	(revision 993)
+++ /pjproject/branches/pjproject-0.5-stable/pjlib/src/pj/config.c	(revision 994)
@@ -22,5 +22,5 @@
 
 static const char *id = "config.c";
-const char *PJ_VERSION = "0.5.10.1";
+const char *PJ_VERSION = "0.5.10.2-pre";
 
 PJ_DEF(void) pj_dump_config(void)
Index: /pjproject/branches/pjproject-0.5-stable/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- /pjproject/branches/pjproject-0.5-stable/pjsip-apps/src/pjsua/pjsua_app.c	(revision 993)
+++ /pjproject/branches/pjproject-0.5-stable/pjsip-apps/src/pjsua/pjsua_app.c	(revision 994)
@@ -2285,9 +2285,29 @@
 
 	    } else {
+		int st_code;
+		char contact[120];
+		pj_str_t hname = { "Contact", 7 };
+		pj_str_t hvalue;
+		pjsip_generic_string_hdr hcontact;
+		pjsua_msg_data msg_data;
+
 		if (!simple_input("Answer with code (100-699)", buf, sizeof(buf)))
 		    continue;
 		
-		if (my_atoi(buf) < 100)
+		st_code = my_atoi(buf);
+		if (st_code < 100)
 		    continue;
+
+		pjsua_msg_data_init(&msg_data);
+
+		if (st_code/100 == 3) {
+		    if (!simple_input("Enter URL to be put in Contact", 
+				      contact, sizeof(contact)))
+			continue;
+		    hvalue = pj_str(contact);
+		    pjsip_generic_string_hdr_init2(&hcontact, &hname, &hvalue);
+
+		    pj_list_push_back(&msg_data.hdr_list, &hcontact);
+		}
 
 		/*
@@ -2302,5 +2322,5 @@
 		}
 
-		pjsua_call_answer(current_call, my_atoi(buf), NULL, NULL);
+		pjsua_call_answer(current_call, st_code, NULL, &msg_data);
 	    }
 
Index: /pjproject/branches/pjproject-0.5-stable/pjsip/src/pjsip/sip_dialog.c
===================================================================
--- /pjproject/branches/pjproject-0.5-stable/pjsip/src/pjsip/sip_dialog.c	(revision 993)
+++ /pjproject/branches/pjproject-0.5-stable/pjsip/src/pjsip/sip_dialog.c	(revision 994)
@@ -1151,4 +1151,5 @@
 /* Add standard headers for certain types of response */
 static void dlg_beautify_response(pjsip_dialog *dlg,
+				  pj_bool_t add_headers,
 				  int st_code,
 				  pjsip_tx_data *tdata)
@@ -1165,11 +1166,15 @@
 
     /* Contact, Allow, Supported header. */
-    if (pjsip_method_creates_dialog(&cseq->method)) {
+    if (add_headers && pjsip_method_creates_dialog(&cseq->method)) {
 	/* Add Contact header for 1xx, 2xx, 3xx and 485 response. */
 	if (st_class==2 || st_class==3 || (st_class==1 && st_code != 100) ||
 	    st_code==485) 
 	{
+	    pj_str_t hcontact = { "Contact", 7 };
+
 	    /* Add contact header only if one is not present. */
-	    if (pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL) == 0) {
+	    if (pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL) == 0 &&
+		pjsip_msg_find_hdr_by_name(tdata->msg, &hcontact, NULL) == 0) 
+	    {
 		hdr = pjsip_hdr_clone(tdata->pool, dlg->local.contact);
 		pjsip_msg_add_hdr(tdata->msg, hdr);
@@ -1242,5 +1247,5 @@
     pjsip_dlg_inc_lock(dlg);
 
-    dlg_beautify_response(dlg, st_code, tdata);
+    dlg_beautify_response(dlg, PJ_FALSE, st_code, tdata);
 
     /* Unlock the dialog. */
@@ -1260,5 +1265,6 @@
 						const pj_str_t *st_text)
 {
-    
+    pjsip_hdr *hdr;
+
     PJ_ASSERT_RETURN(dlg && tdata && tdata->msg, PJ_EINVAL);
     PJ_ASSERT_RETURN(tdata->msg->type == PJSIP_RESPONSE_MSG,
@@ -1277,5 +1283,13 @@
     }
 
-    dlg_beautify_response(dlg, st_code, tdata);
+    /* Remove existing Contact header (without this, when dialog sent 
+     * 180 and then 302, the Contact in 302 will not get updated).
+     */
+    hdr = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
+    if (hdr)
+	pj_list_erase(hdr);
+
+    /* Add tag etc. if necessary */
+    dlg_beautify_response(dlg, PJ_FALSE, st_code, tdata);
 
 
@@ -1325,4 +1339,9 @@
     /* Must acquire dialog first, to prevent deadlock */
     pjsip_dlg_inc_lock(dlg);
+
+    /* Last chance to add mandatory headers before the response is
+     * sent.
+     */
+    dlg_beautify_response(dlg, PJ_TRUE, tdata->msg->line.status.code, tdata);
 
     /* If the dialog is locked to transport, make sure that transaction
