Index: pjproject/trunk/pjsip/include/pjsip-ua/sip_inv.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip-ua/sip_inv.h	(revision 5108)
+++ pjproject/trunk/pjsip/include/pjsip-ua/sip_inv.h	(revision 5109)
@@ -479,5 +479,5 @@
  *			this to NULL, to let remote UAS specifies an offer.
  * @param options	The options argument is bitmask combination of SIP 
- *			features in pjsip_inv_options enumeration.
+ *			features in pjsip_inv_option enumeration.
  * @param p_inv		On successful return, the invite session will be put 
  *			in this argument.
@@ -616,5 +616,5 @@
  *			matches the offer. 
  * @param options	The options argument is bitmask combination of SIP 
- *			features in pjsip_inv_options enumeration.
+ *			features in pjsip_inv_option enumeration.
  * @param p_inv		Pointer to receive the newly created invite session.
  *
Index: pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c	(revision 5108)
+++ pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c	(revision 5109)
@@ -1676,4 +1676,65 @@
 }
 
+/* Utility to remove a string value from generic array header */
+static void remove_val_from_array_hdr(pjsip_generic_array_hdr *arr_hdr,
+				      const pj_str_t *val)
+{
+    unsigned i;
+    for (i=0; i<arr_hdr->count; ++i) {
+	if (pj_stricmp(&arr_hdr->values[i], val)==0) {
+	    pj_array_erase(arr_hdr->values, sizeof(arr_hdr->values[0]),
+			   arr_hdr->count, i);
+	    --arr_hdr->count;
+	    break;
+	}
+    }
+}
+
+
+/* Remove disabled extensions, e.g: timer & 100rel, from Allow/Supported
+ * headers (see ticket #1858).
+ */
+static void cleanup_allow_sup_hdr(unsigned inv_option,
+				  pjsip_tx_data *tdata,
+				  pjsip_allow_hdr *allow_hdr,
+				  pjsip_supported_hdr *sup_hdr)
+{
+    /* If all extensions are enabled, nothing to do */
+    if ((inv_option & PJSIP_INV_SUPPORT_100REL) &&
+	(inv_option & PJSIP_INV_SUPPORT_TIMER))
+    {
+	return;
+    }
+
+    if (!allow_hdr && tdata) {
+	allow_hdr = (pjsip_allow_hdr*) pjsip_msg_find_hdr(tdata->msg,
+							  PJSIP_H_ALLOW,
+							  NULL);
+    }
+    if (!sup_hdr && tdata) {
+	sup_hdr = (pjsip_supported_hdr*) pjsip_msg_find_hdr(tdata->msg,
+							    PJSIP_H_SUPPORTED,
+							    NULL);
+    }
+
+    /* Remove "timer" from Supported header if Session-Timers is
+     * disabled (https://trac.pjsip.org/repos/ticket/1761)
+     */
+    if ((inv_option & PJSIP_INV_SUPPORT_TIMER) == 0 && sup_hdr) {
+	const pj_str_t STR_TIMER = { "timer", 5 };
+	remove_val_from_array_hdr(sup_hdr, &STR_TIMER);
+    }
+
+    if ((inv_option & PJSIP_INV_SUPPORT_100REL) == 0) {
+	const pj_str_t STR_PRACK  = { "PRACK", 5 };
+	const pj_str_t STR_100REL = { "100rel", 6 };
+
+	if (allow_hdr)
+	    remove_val_from_array_hdr(allow_hdr, &STR_PRACK);
+	if (sup_hdr)
+	    remove_val_from_array_hdr(sup_hdr, &STR_100REL);
+    }
+}
+
 /*
  * Create initial INVITE request.
@@ -1684,4 +1745,6 @@
     pjsip_tx_data *tdata;
     const pjsip_hdr *hdr;
+    pjsip_allow_hdr *allow_hdr = NULL;
+    pjsip_supported_hdr *sup_hdr = NULL;
     pj_bool_t has_sdp;
     pj_status_t status;
@@ -1751,6 +1814,7 @@
 	hdr = pjsip_endpt_get_capability(inv->dlg->endpt, PJSIP_H_ALLOW, NULL);
 	if (hdr) {
-	    pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)
-			      pjsip_hdr_shallow_clone(tdata->pool, hdr));
+	    allow_hdr = (pjsip_allow_hdr*)
+			pjsip_hdr_shallow_clone(tdata->pool, hdr);
+	    pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)allow_hdr);
 	}
     }
@@ -1759,25 +1823,11 @@
     hdr = pjsip_endpt_get_capability(inv->dlg->endpt, PJSIP_H_SUPPORTED, NULL);
     if (hdr) {
-	pjsip_supported_hdr *h_sup;
-
-	h_sup = (pjsip_supported_hdr*) pjsip_hdr_clone(tdata->pool, hdr);
-	/* Remove "timer" from Supported header if Session-Timers is
-	 * disabled (https://trac.pjsip.org/repos/ticket/1761)
-	 */
-	if ((inv->options & PJSIP_INV_SUPPORT_TIMER) == 0) {
-	    unsigned i;
-	    const pj_str_t STR_TIMER = { "timer", 5 };
-	    for (i=0; i<h_sup->count; ++i) {
-		if (pj_stricmp(&h_sup->values[i], &STR_TIMER)==0) {
-		    pj_array_erase(h_sup->values, sizeof(h_sup->values[0]),
-		                   h_sup->count, i);
-		    --h_sup->count;
-		    break;
-		}
-	    }
-	}
-
-	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)h_sup);
-    }
+	sup_hdr = (pjsip_supported_hdr*)
+		   pjsip_hdr_shallow_clone(tdata->pool, hdr);
+	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)sup_hdr);
+    }
+
+    /* Cleanup Allow & Supported headers from disabled extensions */
+    cleanup_allow_sup_hdr(inv->options, NULL, allow_hdr, sup_hdr);
 
     /* Add Require header. */
@@ -2229,4 +2279,7 @@
     }
 
+    /* Cleanup Allow & Supported headers from disabled extensions */
+    cleanup_allow_sup_hdr(inv->options, tdata, NULL, NULL);
+
     /* Save this answer */
     inv->last_answer = tdata;
@@ -2292,4 +2345,7 @@
     /* Invoke Session Timers */
     pjsip_timer_update_resp(inv, last_res);
+
+    /* Cleanup Allow & Supported headers from disabled extensions */
+    cleanup_allow_sup_hdr(inv->options, last_res, NULL, NULL);
 
     *p_tdata = last_res;
@@ -2883,4 +2939,5 @@
     pjmedia_sdp_session *sdp_copy;
     const pjsip_hdr *hdr;
+    pjsip_supported_hdr *sup_hdr = NULL;
     pj_status_t status = PJ_SUCCESS;
 
@@ -2958,24 +3015,7 @@
     hdr = pjsip_endpt_get_capability(inv->dlg->endpt, PJSIP_H_SUPPORTED, NULL);
     if (hdr) {
-	pjsip_supported_hdr *h_sup;
-
-	h_sup = (pjsip_supported_hdr*) pjsip_hdr_clone(tdata->pool, hdr);
-	/* Remove "timer" from Supported header if Session-Timers is
-	 * disabled (https://trac.pjsip.org/repos/ticket/1761)
-	 */
-	if ((inv->options & PJSIP_INV_SUPPORT_TIMER) == 0) {
-	    unsigned i;
-	    const pj_str_t STR_TIMER = { "timer", 5 };
-	    for (i=0; i<h_sup->count; ++i) {
-		if (pj_stricmp(&h_sup->values[i], &STR_TIMER)==0) {
-		    pj_array_erase(h_sup->values, sizeof(h_sup->values[0]),
-		                   h_sup->count, i);
-		    --h_sup->count;
-		    break;
-		}
-	    }
-	}
-
-	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)h_sup);
+	sup_hdr = (pjsip_supported_hdr*)
+		   pjsip_hdr_shallow_clone(tdata->pool, hdr);
+	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)sup_hdr);
     }
 
@@ -2983,4 +3023,7 @@
     if (status != PJ_SUCCESS)
 	goto on_error;
+
+    /* Cleanup Allow & Supported headers from disabled extensions */
+    cleanup_allow_sup_hdr(inv->options, NULL, NULL, sup_hdr);
 
     /* Unlock dialog. */
