diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index d54bffa0c7..38cfc69b1b 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -310,6 +310,21 @@ static int registrar_validate_path(pjsip_rx_data *rdata, struct ast_sip_aor *aor
 	return -1;
 }
 
+static int register_add_hdr_contact(struct ao2_container *hdr_contacts, char *contact_uri)
+{
+	struct ast_variable *var;
+	RAII_VAR(struct ast_sip_contact *, uri_contact, NULL, ao2_cleanup);
+
+	var = ast_variable_new("uri", contact_uri, "");
+	if ((uri_contact = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "contact", 0, var))) {
+		ao2_link(hdr_contacts, uri_contact);
+		return 1;
+	}
+	ast_free(var);
+
+	return 0;
+}
+
 static int register_aor_core(pjsip_rx_data *rdata,
 	struct ast_sip_endpoint *endpoint,
 	struct ast_sip_aor *aor,
@@ -334,10 +349,14 @@ static int register_aor_core(pjsip_rx_data *rdata,
 	pjsip_cid_hdr *call_id_hdr;
 	char *call_id = NULL;
 	size_t alloc_size;
+	struct ao2_container *hdr_contacts;
+	int has_expiration = 0;
 
 	/* So we don't count static contacts against max_contacts we prune them out from the container */
 	ao2_callback(contacts, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, registrar_prune_static, NULL);
 
+	hdr_contacts = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 1, NULL, NULL);
+
 	if (registrar_validate_contacts(rdata, contacts, aor, &added, &updated, &deleted)) {
 		/* The provided Contact headers do not conform to the specification */
 		pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 400, NULL, NULL, NULL);
@@ -415,6 +434,7 @@ static int register_aor_core(pjsip_rx_data *rdata,
 		}
 
 		expiration = registrar_get_expiration(aor, contact_hdr, rdata);
+		has_expiration |= expiration;
 		details.uri = pjsip_uri_get_uri(contact_hdr->uri);
 		pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, details.uri, contact_uri, sizeof(contact_uri));
 
@@ -445,6 +465,8 @@ static int register_aor_core(pjsip_rx_data *rdata,
 					aor_name,
 					expiration,
 					user_agent);
+
+			register_add_hdr_contact(hdr_contacts, contact_uri);
 		} else if (expiration) {
 			struct ast_sip_contact *contact_update;
 
@@ -452,6 +474,7 @@ static int register_aor_core(pjsip_rx_data *rdata,
 			if (!contact_update) {
 				ast_log(LOG_ERROR, "Failed to update contact '%s' expiration time to %d seconds.\n",
 					contact->uri, expiration);
+				register_add_hdr_contact(hdr_contacts, contact_uri);
 				continue;
 			}
 
@@ -472,6 +495,7 @@ static int register_aor_core(pjsip_rx_data *rdata,
 				ast_log(LOG_ERROR, "Failed to update contact '%s' expiration time to %d seconds.\n",
 					contact->uri, expiration);
 				ast_sip_location_delete_contact(contact);
+				register_add_hdr_contact(hdr_contacts, contact_uri);
 				continue;
 			}
 			ast_debug(3, "Refreshed contact '%s' on AOR '%s' with new expiration of %d seconds\n",
@@ -485,6 +509,7 @@ static int register_aor_core(pjsip_rx_data *rdata,
 					aor_name,
 					expiration,
 					contact_update->user_agent);
+			register_add_hdr_contact(hdr_contacts, contact_uri);
 			ao2_cleanup(contact_update);
 		} else {
 			/* We want to report the user agent that was actually in the removed contact */
@@ -517,6 +542,7 @@ static int register_aor_core(pjsip_rx_data *rdata,
 	if (ast_sip_create_response(rdata, 200, response_contact, &tdata) != PJ_SUCCESS) {
 		ao2_cleanup(response_contact);
 		ao2_cleanup(contacts);
+		ao2_cleanup(hdr_contacts);
 		return PJ_TRUE;
 	}
 	ao2_cleanup(response_contact);
@@ -524,8 +550,14 @@ static int register_aor_core(pjsip_rx_data *rdata,
 	/* Add the date header to the response, some UAs use this to set their date and time */
 	registrar_add_date_header(tdata);
 
-	ao2_callback(contacts, 0, registrar_add_contact, tdata);
+	if (ao2_container_count(hdr_contacts)) {
+		ao2_callback(hdr_contacts, 0, registrar_add_contact, tdata);
+	} else if (has_expiration) {
+		ao2_callback(contacts, 0, registrar_add_contact, tdata);
+	}
+
 	ao2_cleanup(contacts);
+	ao2_cleanup(hdr_contacts);
 
 	if ((expires_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES, NULL))) {
 		expires_hdr = pjsip_expires_hdr_create(tdata->pool, registrar_get_expiration(aor, NULL, rdata));
